You are viewing a single comment's thread. Return to all comments →
Thanks. I started messing around Set<String>
Set<String>
I see that you can create unique sets of Strings.
Set<String> set1 = new TreeSet<String>(); Set<String> set2 = new TreeSet<String>(); set1.add("dog"); set1.add("cat"); set1.add("mouse"); set1.add("snake"); set1.add("bear"); set2.add("mouse"); set2.add("cat"); set2.add("bee"); set2.add("ant"); set2.add("spider"); set1.retainAll(set2);
set1 now contains Cat & Mouse.
So using the isEmpty you can check if there is similarity.
isEmpty
if(set1.isEmpty()) System.out.println("NO"); else System.out.println("YES");
These are examples with strings. So I assume it's just as easy using char.
Seems like cookies are disabled on this browser, please enable them to open this website
Two Strings
You are viewing a single comment's thread. Return to all comments →
Thanks. I started messing around
Set<String>
I see that you can create unique sets of Strings.
set1 now contains Cat & Mouse.
So using the
isEmpty
you can check if there is similarity.These are examples with strings. So I assume it's just as easy using char.