java - Find disjoint set irrespective of case of the strings -
i using collection.disjoint find disjoint set of 2 string collections c1, c2.
not ignore cases, example - string str
different str
.
return collections.disjoint(c1, c2);
can find disjoint of both collections ignoring cases without using loop?
if absolutely insist no for
loop used, can find disjoint between 2 collection
s of lowercased string
s. using google guava, should like:
package ru.zombator.stackoverflow; import java.util.arrays; import java.util.collection; import java.util.collections; import java.util.locale; import com.google.common.base.function; import com.google.common.collect.collections2; public final class disjointignorecase { public static void main(string[] args) { collection<string> coll1 = arrays.aslist("donald", "duck"); collection<string> coll2 = arrays.aslist("donald", "donut"); collection<string> coll3 = arrays.aslist("homer", "donut"); collection<string> coll4 = arrays.aslist("donald", "duck"); // print false system.out.println(disjointignorecase(coll1, coll2)); system.out.println(disjointignorecase(coll2, coll3)); system.out.println(disjointignorecase(coll1, coll4)); // print true (no common elements) system.out.println(disjointignorecase(coll1, coll3)); } private static boolean disjointignorecase(collection<string> coll1, collection<string> coll2) { return collections.disjoint(lowercased(coll1), lowercased(coll2)); } private static collection<string> lowercased(collection<string> coll) { return collections2.transform(coll, new function<string, string>() { @override public string apply(string input) { return input.tolowercase(locale.us); } }); } }
Comments
Post a Comment