Skip to content

Instantly share code, notes, and snippets.

@clarkdo
Created December 21, 2017 08:48
Show Gist options
  • Select an option

  • Save clarkdo/233cd35a3e62820455b8dd6595d7fb76 to your computer and use it in GitHub Desktop.

Select an option

Save clarkdo/233cd35a3e62820455b8dd6595d7fb76 to your computer and use it in GitHub Desktop.
import com.google.common.collect.Lists;
import java.util.ArrayList;
import java.util.List;
public class SearchInList {
public static final ArrayList<List<String>> LIST = Lists.newArrayList(
Lists.newArrayList("a", "b"),
Lists.newArrayList("c", "d"),
Lists.newArrayList("e", "f", "g"),
Lists.newArrayList("h", "i", "j", "k"),
Lists.newArrayList("l", "m", "n", "o")
);
public static final boolean containsIn2D (List<List<String>> list, String str) {
return list.stream().flatMap(l -> l.parallelStream()).anyMatch(v -> v.equals(str));
}
public static void main(String[] args) {
System.out.println(containsIn2D(LIST, "a"));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment