Java Collections contains Substring

By default list.contains(“String”) check for complete match in each line, so searching for list.contain(“ing”) would return false.

This is what I did for solution:

Convert list collection to String and then search in this complete Collection String contains our substring “ing”

Example: sample code below list elements in list1 that are not present in list2.  Also while comparing it compares only for first 7 characters

String x = list2.toString();
for(String a:list1){
   String b = a.substring(0,7);


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s