api 문서
http://docs.guava-libraries.googlecode.com/git/javadoc/com/google/common/collect/Lists.html
Lists에서 자주 사용하는 것은 생성할 때이다.
Lists.newArrayList();
Lists.newLinkedList();
Lists.newArrayListWithExpectedSize(person.size());
List<byte[]> list = Lists.newArrayList(Bytes.toBytes("request"), Bytes.toBytes("init"));
import java.util.Arrays;
import java.util.List;
import org.junit.Test;
import com.google.common.base.Function;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
public class GuavaTest {
@Test
public void test1() {
List<Integer> lists = Arrays.asList(1, 2, 3, 4, 5, 6, 7);
List<List<Integer>> pages = Lists.partition(lists, 3);
System.out.println(pages);
}
@Test
public void test2() {
ImmutableList<String> numberString = new ImmutableList.Builder<String>()
.add("11111")
.add("22222")
.add("33333")
.add("44444")
.build();
List<Integer> result = Lists.transform(numberString, new Function<String, Integer>() {
@Override
public Integer apply(String value) {
return Integer.parseInt(value);
}
});
System.out.println(result);
}
}
결과
[[1, 2, 3], [4, 5, 6], [7]]
[11111, 22222, 33333, 44444]
'general java' 카테고리의 다른 글
[Guava] Collections2.filter (0) | 2015.04.14 |
---|---|
[Guava] Multimap 예제 (0) | 2015.04.11 |
[Guava] ImmutableMap, ImmutableSet, ImmutableList 예제 (0) | 2015.04.10 |
[Guava] Iterables.transform 과 removeIf 예제 (0) | 2015.04.10 |
[Guava] Joiner와 Splitter 예제 (0) | 2015.04.09 |