java 数组和列表

定义一个数组

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)

后面会加上数组和列表的相互操作

  1. Arrays.sort(asList.toArray(new String[asList.size()]),String::compareToIgnoreCase);
  2. List asList = Arrays.asList(“dada”,“daada”,“daada”);

集合框架知识点

  1. for each循环翻译为 带有迭代器的循环,标准库的任何集合都可以用for each: for(String s : strs)
  2. 访问顺序取决于类型,arraylist 会从0 开始,hashset会按照某种随机的次序出现
  3. iterator 的方法: next(),hasnext(),remove():remove 会删除上次调用next方法返回的元素。remove和next是有依赖性的,得先next再remove
  4. 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)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值