Last active
August 29, 2015 14:06
-
-
Save tag1216/5b1c4004a17a86a04486 to your computer and use it in GitHub Desktop.
連休だしJavaコレクションの歴史を振り返ってみる ref: http://qiita.com/tag1216/items/3f222ae3cae88210f769
This file contains hidden or 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
persons.sort(Comparator.comparing( | |
Person::getLastName, Comparator.reverseOrder())); |
This file contains hidden or 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
Vector list = new Vector(); | |
list.add(new Integer(9)); | |
list.add(new Integer(3)); | |
list.add(new Integer(4)); | |
Enumeration e = list.elements(); | |
while (e.hasMoreElements()) { | |
Integer val = (Integer) e.nextElement(); | |
System.out.println(val); | |
} | |
for (int i = 0; i < list.size(); i++) { | |
System.out.println(list.elementAt(i)); | |
} |
This file contains hidden or 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
List list = new ArrayList(); | |
list.add(new Integer(9)); | |
list.add(new Integer(3)); | |
list.add(new Integer(4)); | |
Iterator itr = list.iterator(); | |
while (itr.hasNext()) { | |
Integer val = (Integer) itr.next(); | |
System.out.println(val); | |
} | |
for (int i = 0; i < list.size(); i++) { | |
System.out.println(list.get(i)); | |
} |
This file contains hidden or 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
Collections.sort(list, new Comparator() { | |
public int compare(Object o1, Object o2) { | |
return ((Integer) o1).compareTo((Integer) o2); | |
} | |
}); |
This file contains hidden or 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
List<Integer> list = new ArrayList<Integer>(); | |
list.add(9); | |
list.add(3); | |
list.add(4); | |
for (int val : list) { | |
System.out.println(val); | |
} |
This file contains hidden or 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
List<Integer> list = Arrays.asList(9, 3, 4); |
This file contains hidden or 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
List<Integer> list = new ArrayList<>(); |
This file contains hidden or 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
IntStream.rangeClosed(1, 10) | |
.filter(x -> x % 3 == 0) | |
.map(x -> x * 2) | |
.sum(); |
This file contains hidden or 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
list.sort((x, y) -> {return x - y;}); |
This file contains hidden or 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
List<Integer> list = Arrays.asList(9, 3, 4); | |
list.forEach(System.out::println); |
This file contains hidden or 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
List<Integer> list = Arrays.asList(9, 3, 4); | |
list.forEach(val -> System.out.println(val)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment