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"));




Lists.partition()으로 partition(또는 paging) 처리를 할 수 있다. 
그리고, List.transform()으로 다른 타입을 갖는 List로 만들 수 있다. 

예제


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]

Posted by '김용환'
,