1. 填充容器
Collection Framework中有2个工具类,分别是Collections和Arrays类,这2个类有很多静态方法,可以完成集合的操作。
Collections 类:
static <T> List<T> nCopies(int n, T o):
Returns an immutable list consisting of n copies of the specified object
static <T> void fill(List<? super T> list, T obj)
Replaces all of the elements of the specified list with the specified element.
ArrayList<Airtest> list = new ArrayList(Collections.nCopies(4, new Airtest("airtest")));
System.out.println(list);
Collections.fill(list, new Airtest("testair"));
System.out.println(list);
1. Map:
标准java类库中包含Map的几种基本实现,包括:HashMap,TreeMap,LinkedHashMap,WeakHashMap,ConcurrentHashMap,IdentityHashMap。
HashMap使用散列码来进行搜索。散列码是相对唯一的、用以代表对象的int值,通过将该对象的某些信息进行转换而生成。hashCode()是根类Object中的方法,所有java对象都可以产生散列码。