list intersection java
I have two arraylists and I want intersection (means, common elements in both arraylists).
Refer this link,
http://stackoverflow.com/questions/2400838/efficient-intersection-of-two-liststring-in-java
http://www.devmanuals.com/tutorials/java/collections/ListRetainAll.html
I have two arraylists and I want intersection (means, common elements in both arraylists).
Refer this link,
http://stackoverflow.com/questions/2400838/efficient-intersection-of-two-liststring-in-java
http://www.devmanuals.com/tutorials/java/collections/ListRetainAll.html
retainAll() can be used to achieve this.
ArrayList<String> big=new ArrayList<String();
big.add("1");
big.add("2");
big.add("3");
big.add("4");
big.add("5");
big.add("6");
ArrayList<String> small=new ArrayList<String();
small.add("1");
small.add("2");
small.add("3");
boolean b=big.retainAll(small);
No comments:
Post a Comment