标签:style blog io ar color sp java on div
1 操作Collection及Map工具类
package lianxi2; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; import org.junit.Test; public class TestCollections { @Test public void test1(){ List list = new ArrayList(); list.add(3242); list.add(23); list.add(55); list.add(2233); list.add(90); System.out.println(list); System.out.println(Collections.max(list)); Collections.reverse(list); System.out.println(list); Collections.swap(list, 3, 4); System.out.println(list); //copy()方法 List list1 = Arrays.asList(new Object[list.size()]); Collections.copy(list1, list); System.out.println("list1="+list); //保证线程安全 List list2 = Collections.synchronizedList(list); System.out.println("list2="+list2); } }
结果:
[3242, 23, 55, 2233, 90]
3242
[90, 2233, 55, 23, 3242]
[90, 2233, 55, 3242, 23]
list1=[90, 2233, 55, 3242, 23]
list2=[90, 2233, 55, 3242, 23]
标签:style blog io ar color sp java on div
原文地址:http://www.cnblogs.com/yjtm53/p/4150031.html