zoukankan      html  css  js  c++  java
  • 删除list中指定值的元素

    public class ListRemoveAll {

     
     public static void main(String[] args) {
      // TODO Auto-generated method stub
      List<Long> list1 = new ArrayList<Long>();
      List<Long> list2 = new ArrayList<Long>();
      for(int i =0;i<10;i++){
       list1.add(Long.parseLong(i+""));
       list2.add(Long.parseLong(i+""));
      }
      for(int i =10;i<20;i++){
       list1.add(Long.parseLong(i+""));
      }
      list1.add(55L);
      System.out.println(list1.toString());
      System.out.println(list2.toString());
      list1.remove(55L);
      System.out.println(list1.toString());
     }

    }

    其结果为

    [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 55]
    [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
    [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]

    原来list.remove();不只是可以删除所引元素,也可以删除object

  • 相关阅读:
    memcache
    memcache 杂记
    mysql_函数
    MySQL_存储过程
    MySQL_视图
    mysql _触发器
    MySQL_优化
    mysql_索引
    R语言编程艺术_第六章_因子和表
    Bioinfo:学习Python,做生信PartII 学习笔记
  • 原文地址:https://www.cnblogs.com/sily-boy/p/4874134.html
Copyright © 2011-2022 走看看