定义一个数组
String[] strings = new String[10]; 自己老是忘记写长度
String[] Strings = {“dada”,“dada”,“dadadada”},在作为参数是不能这样写,应该写成 new String[]{“dada”,“dada”,“dadadada”}
数组的一些常用API
- Arrays.toString()
- Arrays.copyOf(String[] original, int newLength)
- Arrays…sort(Object[] a)
- Arrays.binarySearch(Object[] a, Object key) The array must be sorted into ascending order according to the specified comparator (as by the sort(T[], Comparator) method) prior to making this call
- void java.util.Arrays.fill(Object[] a, Object val)
后面会加上数组和列表的相互操作
- Arrays.sort(asList.toArray(new String[asList.size()]),String::compareToIgnoreCase);
- List asList = Arrays.asList(“dada”,“daada”,“daada”);
集合框架知识点
- for each循环翻译为 带有迭代器的循环,标准库的任何集合都可以用for each: for(String s : strs)
- 访问顺序取决于类型,arraylist 会从0 开始,hashset会按照某种随机的次序出现
- iterator 的方法: next(),hasnext(),remove():remove 会删除上次调用next方法返回的元素。remove和next是有依赖性的,得先next再remove
- collection 的方法:iterator(),size(),isEmpty(),contains(Object),containsAll(Collection<?> other),add(Object),addAll(Collection<?> other),
remove(Object ),removeAll(Collection<?> other),clear(),retainAll(Collection<?> other) 删除所有与other集合元素不同的元素,toArray(),toArray(T[] arrtyToFill)