import java.util.List;
import org.hamcrest.CoreMatchers;
import org.junit.Assert;
import com.google.common.collect.Lists;/*** TODO 在此写上类的相关说明.<br>* @author gqltt<br>* @version 1.0.0 2021年11月12日<br>* @see * @since JDK 1.5.0*/
public class ListsDemo {public static void main(String[] args) {newList();reverse();partition();}/*** 新建list.*/static void newList() {List<Integer> emptyList = Lists.newArrayList();List<Integer> numbers = Lists.newArrayList(1, 2, 3, 4);}/*** 列表反转.*/static void reverse() {List<Integer> numbers = Lists.newArrayList(1, 2, 3, 4);List<Integer> expected = Lists.newArrayList(4, 3, 2, 1);List<Integer> reversed = Lists.reverse(numbers);Assert.assertThat(expected, CoreMatchers.is(reversed));}/*** 列表分组.*/static void partition() {Lists.newArrayList();List<Integer> numbers = Lists.newArrayList(1, 2, 3, 4);List<List<Integer>> subLists = Lists.partition(numbers, 2);Assert.assertThat(subLists.get(0), CoreMatchers.is(Lists.newArrayList(1, 2)));Assert.assertThat(subLists.get(1), CoreMatchers.is(Lists.newArrayList(3, 4)));}
}