general java
[guava] Iterables.concat
'김용환'
2016. 4. 14. 00:22
Iterables.concat()는 여러 리스트를 하나의 리스트로 합치는 기능을 가진다.
final List<Integer> list1 = Lists.newArrayList(1, 2, 3);
final List<Integer> list2 = Lists.newArrayList(100, 200, 300);
System.out.println(Iterables.concat(list1, list2));
결과
[1, 2, 3, 100, 200, 300]
기억할 필요가 있는 것은 타입이 달라도 하나로 합칠 수 있다는 점이다.
final List<String> list1 = Lists.newArrayList("a", "b", "c");
final List<Integer> list2 = Lists.newArrayList(4, 5, 6);
System.out.println(Iterables.concat(list1, list2));
결과
[a, b, c, 4, 5, 6]