Created
September 3, 2015 21:57
-
-
Save aratakokubun/0c7e87876627ccee4dd5 to your computer and use it in GitHub Desktop.
Javaの差分リスト ref: http://qiita.com/aratakokubun/items/4158427b4d9ce4078312
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ArrayList<String> arr1 = new ArrayList<String>() { | |
private static final long serialVersionUID = 1L; | |
{ | |
add("a"); | |
add("b"); | |
add("c"); | |
add("d"); | |
add("e"); | |
} | |
}; | |
ArrayList<String> arr2 = new ArrayList<String>(arr1); | |
arr2.remove(0); | |
arr2.remove(0); | |
arr2.add("f"); | |
System.out.println("arr1"); | |
for (String s : arr1) { | |
System.out.println(s); | |
} | |
System.out.println("--------"); | |
System.out.println("arr2"); | |
for (String s : arr2) { | |
System.out.println(s); | |
} | |
System.out.println("--------"); | |
System.out.println(); | |
ArrayList<String> subArr1 = new ArrayList<String>(arr1); | |
subArr1.removeAll(arr2); | |
System.out.println("subArr1"); | |
for (String s : subArr1) { | |
System.out.println(s); | |
} | |
System.out.println("-------"); | |
ArrayList<String> subArr2 = new ArrayList<String>(arr2); | |
subArr2.removeAll(arr1); | |
System.out.println("subArr2"); | |
for (String s: subArr2) { | |
System.out.println(s); | |
} | |
System.out.println("-------"); | |
System.out.println(); | |
Set<String> set1 = new HashSet<String>(); | |
set1.add("a"); | |
set1.add("b"); | |
set1.add("c"); | |
set1.add("d"); | |
set1.add("e"); | |
Set<String> set2 = new HashSet<String>(set1); | |
set2.remove("a"); | |
set2.remove("b"); | |
set2.add("f"); | |
System.out.println("set1"); | |
for (String s : set1) { | |
System.out.println(s); | |
} | |
System.out.println("--------"); | |
System.out.println("set2"); | |
for (String s : set2) { | |
System.out.println(s); | |
} | |
System.out.println("-------"); | |
System.out.println(); | |
Set<String> subSet1 = new HashSet<String>(set1); | |
subSet1.removeAll(set2); | |
System.out.println("subSet1"); | |
for (String s : subSet1) { | |
System.out.println(s); | |
} | |
System.out.println("-------"); | |
Set<String> subSet2 = new HashSet<String>(set2); | |
System.out.println("subSet2"); | |
subSet2.removeAll(set1); | |
for (String s: subSet2) { | |
System.out.println(s); | |
} | |
System.out.println("-------"); | |
System.out.println(); | |
ArrayList<String> subArrWithSet = new ArrayList<String>(set1); | |
subArrWithSet.removeAll(arr2); | |
System.out.println("subArrWithSet"); | |
for (String s : subArrWithSet) { | |
System.out.println(s); | |
} | |
System.out.println("-------"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
arr1 | |
a | |
b | |
c | |
d | |
e | |
-------- | |
arr2 | |
c | |
d | |
e | |
f | |
-------- | |
subArr1 | |
a | |
b | |
------- | |
subArr2 | |
f | |
------- | |
set1 | |
a | |
b | |
c | |
d | |
e | |
-------- | |
set2 | |
c | |
d | |
e | |
f | |
------- | |
subSet1 | |
a | |
b | |
------- | |
subSet2 | |
f | |
------- | |
subArrWithSet | |
a | |
b | |
------- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment