首页 > 其他分享 >List集合

List集合

时间:2024-03-06 11:13:34浏览次数:19  
标签:integers List System remove add 集合 out

List

List集合的特点有序、可重复、有索引。

List remove重载方法的细节

List的remove方法有两个

  • 案例一
  public static void main(String[] args) {
      List<Integer> integers = new ArrayList<Integer>();
      integers.add(1);
      integers.add(2);
      integers.add(3);
      integers.add(4);
      System.out.println(integers);
      integers.remove(1);
      System.out.println(integers);
  }

运行结果

[1, 2, 3, 4]
[1, 3, 4]
  • 案例二
  public static void main(String[] args) {
      List<Integer> integers = new ArrayList<Integer>();
      integers.add(1);
      integers.add(2);
      integers.add(3);
      integers.add(4);
      System.out.println(integers);
      integers.remove(Integer.valueOf(1));
      System.out.println(integers);
  }

运行结果

[1, 2, 3, 4]
[2, 3, 4]

结论:重载方法优先调用实参和形参一致的方法

标签:integers,List,System,remove,add,集合,out
From: https://www.cnblogs.com/poteitoutou/p/18056002

相关文章

  • (21)Lazarus之FilterComboBox1过滤ShellListView1的文件名
    FilterComboBox1只过滤当前目录下的文件名,不过滤目录名,也不过滤子目录名拖一个FilterComboBox1,ShellListView1到界面上1]将FilterComboBox1的ShellListView设置为ShellListView12]添加过滤文件类型 3]还须设置ShellListView1的根目录Root ......
  • lazarus在银河麒麟国产操作系统linux下,使用TListView 使用图标样式 BUG完善
    lazarus在银河麒麟国产操作系统linux下,使用TListView使用TListViewvsIcon样式,文本长了会是这样效果尝试设置OwnerDraw属性为True自己定义方法DrawItem不起效果也尝试修改TCustomListView源代码也不起效果,搞了半天,后发现坑了,没仔细看帮助WhensettoTrue,theOn......
  • CopyOnWriteArrayList
    CopyOnWriteArrayList目录CopyOnWriteArrayListCopyOnWriteArrayList诞生记CopyOnWriteArrayList使用场景CopyOnWriteArrayList读写操作实现原理缺点源码分析CopyOnWriteArrayList诞生记代替Vector和SynchronizedList,就像ConcurrentHashMap代替SynchronizedMap的原因一样Vect......
  • Java集合
    Java集合Java分为单列数据集合和双列数据集合单列数据集合一次存取一个元素双列数据集合一次存取一对元素单列数据集合单列集合的祖宗(Collection)List系列集合:有序(按照添加的顺序存放)、可重复、有索引Set系列集合:无序、不可重复、无索引Collection接口方法其中......
  • List集合中的某个元素的求和
    第一种方式intsuma=list.stream().map(e->e.getAge()).reduce(Integer::sum).get();//求和System.out.println(suma);intmaxa=list.stream().map(e->e.getAge()).reduce(Integer::max).get();//最大System.out.println(maxa);intmina=list.stream().map(e->e.g......
  • (20) Lazarus学习之ListFilterEdit1过滤ListBox1数据
     Delphi我写的类似功能带历史记忆,并模糊带出功能的Edit 先在ListBox1的Items里添加数据 再拖一个ListFilterEdit1要界面上,设置它的 即可看到过滤效果 同样适合CheckListBox1 ......
  • list集合转map 封装
    //list转map很多情况下,需要遍历2层for循环,时间复杂度为O(n的平方),可以借助转map,遍历循环一层for循环,需要的从map中取数据,提升速度,//map的时间复杂度为O(1)可忽略不计,一下是对list转map的封装publicstatic<T,K>Map<K,T>list2Map(List<T>list,Function<?superT......
  • C# 用foreach迭代集合时获取索引
    一般做法是循环外部定义index,内部累加值 staticvoidMain(string[]args){vararr=newList<string>(){"aaa","bbb","ccc"};varindex=0;foreach(varvalinarr){index++;Console.WriteLine($&quo......
  • NTPD monlist Command Enabled|CVE-2013-5211
    NTPDmonlistCommandEnabled|CVE-2013-5211目录NTPDmonlistCommandEnabled|CVE-2013-52111描述2影响范围3漏洞检测3.1Nmap检测4缓解措施5防御措施1描述NTP是用来使计算机时间同步化的一种协议。CVE-2013-5211最早公布是2014年1月10日攻击者HACK发送了一个......
  • List remote Git branches and the last commit's author and author date for each b
    Listingeachbranchanditslastrevision'sdateinGit ListremoteGitbranchesandthelastcommit'sauthorandauthordateforeachbranch.Sortbymostrecentcommit'sauthordate. #Credithttp://stackoverflow.com/a/2514279f......