Java examples for java.util:List Compare
diff two String List and return a List
//package com.book2s; import java.util.ArrayList; import java.util.List; public class Main { public static void main(String[] argv) { List list1 = java.util.Arrays.asList("asdf", "book2s.com"); List list2 = java.util.Arrays.asList("asdf", "book2s.com"); System.out.println(java.util.Arrays.toString(diff(list1, list2))); }// w w w . ja v a 2 s . c o m public static List<String>[] diff(List<String> list1, List<String> list2) { if (list1 == null) list1 = new ArrayList<String>(); if (list2 == null) list2 = new ArrayList<String>(); List<String> toAddList = new ArrayList<String>(); List<String> toDelList = new ArrayList<String>(); for (String str1 : list1) { if (!list2.contains(str1)) { toAddList.add(str1); } } for (String str2 : list2) { if (!list1.contains(str2)) { toDelList.add(str2); } } return new List[] { toAddList, toDelList }; } public static boolean contains(List<Long[]> higherPart, List<Long[]> lowerPart) { if (lowerPart.size() == 0 && higherPart.size() != 0) return true; for (int i = 0; i < lowerPart.size(); i++) { Long[] lPart = lowerPart.get(i); int j = 0; for (j = 0; j < higherPart.size(); j++) { Long[] hPart = higherPart.get(j); if (hPart[0] <= lPart[0] && hPart[1] >= lPart[1]) { // higherTimePart?i????? break; } } if (j == higherPart.size()) { // ????? return false; } } return true; } }