How to remove matched words from end of String
<p>I want to remove the following words from end of String <code>‘PTE’, ‘LTD’, ‘PRIVATE’ and ‘LIMITED’</code></p>

<p>i tried the code but then i stuck. i tried this </p>

<pre><code>String[] str = {"PTE", "LTD", "PRIVATE", "LIMITED"};

String company = "Basit LTD";
for(int i=0;i&lt;str.length;i++) {

    if (company.endsWith(str[i])) {

        int position = company.lastIndexOf(str[i]);
        company = company.substring(0, position);        
    }
}

System.out.println(company.replaceAll("\\s",""));
</code></pre>

<p>It worked. But suppose the company is <code>Basit LIMITED PRIVATE LTD PTE</code> or <code>Basit LIMITED PRIVATE PTE LTD</code> or any combination of four words in the end. Then the above code just remove the last name i.e., <code>PTE</code> or <code>PRIVATE</code> and so on, and the output is <code>BasitLIMITEDPRIVATELTD</code>.</p>

<p>I want output to be just <code>Basit</code></p>

<p>How can i do it?</p>

<p>Thanks</p>

<p><strong>---------------Edit---</strong></p>

<p>Please note here the company name is just an example, it is not necessary that it is always the same. may be i have name like</p>

<pre><code>String company = "Masood LIMITED LTD PTE PRIVATE"
</code></pre>

<p>or any name that can have the above mentioned words at the end.</p>

<p>Thanks</p>
