Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

efficient way of finding indexes of a string which has duplicate elements

843785Sep 25 2008 — edited Sep 26 2008
hi all,
I am new to java, i tried the following way of finding the indexes of duplicae elements. Please help me with much efficient way with less iterations with out using collection classes
public class Sample {

		 public static void main(String[] args) {
		        String[] strs= {"AA","GG","AA","AA","BOB"};
		        ArrayList equalsList=new ArrayList();
		        for(int i=0;i<=4;i++)
		        {
		        	for(int j=0;j<=4;j++)
		        	{
		        		if(strs!=null && !"".equals(strs[i])&& strs[i]==strs[j] && i!=j)
{

System.err.println(i+1+ " ---"+ (j+1));
equalsList.add(i+1);


break;
}
}
}
System.err.println(equalsList);
}
Thanks...                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 24 2008
Added on Sep 25 2008
15 comments
997 views