I want to get the smallest match of strings in the list. Though I'm successful doing so but the problem is i want to count that how many match counts have been made so:
List<String> mylist=new LinkedList<String>();
Set<String> result=new LinkedHashSet<String>();
mylist.add("interpreter");
mylist.add("interprete");
mylist.add("interpret");
mylist.add("developed");
mylist.add("develops");
mylist.add("develop");
mylist.add("interpret");
String small="";
Collections.sort(mylist);
Collections.reverse(mylist);
for(int i=0;i<mylist.size();i++)
{
small=mylist.get(i);
for(int j=i;j<mylist.size();j++)
{
if(small.contains(mylist.get(j)))
{
small=mylist.get(j);
}
}
result.add(small);
}
for (String string : result) {
System.out.println(string);
}
So that the output should be:
interpret=4
develop=4
Problem occurs with the following code i am trying:
List<String> mylist=new LinkedList<String>();
Set<String> result=new LinkedHashSet<String>();
mylist.add("interpreter");
mylist.add("interprete");
mylist.add("interpret");
mylist.add("developed");
mylist.add("develops");
mylist.add("develop");
mylist.add("interpret");
mylist.add("crawler");
mylist.add("crawl");
mylist.add("mobile");
mylist.add("mob");
mylist.add("juni");
mylist.add("junis");
Collections.sort(mylist);
Collections.reverse(mylist);
String small="";
int c=0;
for(int i=0;i<mylist.size();i++)
{
c+=1;
small=mylist.get(i);
for(int j=i;j<mylist.size();j++)
{
if(small.contains(mylist.get(j)))
{
small=mylist.get(j);
c+=1;
}
}
result.add(small);
}
for (String string : result) {
System.out.println(string+"="+c);
}
can somebody help me please!