zoukankan      html  css  js  c++  java
  • 判断List、Map、Set是否为空及效率比较

    //如果object为null,则设置为defaultValue
    ObjectUtils.defaultIfNull(object, defaultValue);
    
    //判断集合是否为null
    List<String> list=new ArrayList<String>();
    System.out.println(list.isEmpty()); //true
    System.out.println(list.size()); //0
    
    Set<String> set=new HashSet<String>();
    System.out.println(set.isEmpty()); //true
    System.out.println(set.size()); //0
    
    Map<String, String> map=new HashMap<String, String>();
    System.out.println(map.isEmpty()); //true
    System.out.println(map.size()); //0
    
    方法一(数据量大,效率低):
    if(list!=null && list.size()>0){
    }
    
    方法二(数据量大,效率高):
    if(list!=null && !list.isEmpty()){
    }

    ---------------------------------------------------------------------------------
    Blog:http://www.cnblogs.com/linjiqin/
    Hadoop交流群(250363249)、Java+Oracle交流群(158560018)

    题外话:
    本人来自铁观音的发源地——泉州安溪,有需要正宗安溪铁观音的友友欢迎Q我:416501600。

  • 相关阅读:
    ajax小白理解
    Once more
    win滚动条样式修改
    NOIP2018游记
    Stirling数笔记
    【Start From Here】HNOI2018 滚粗记
    6面相对象
    5方法定义及调用
    Java4数组
    Java3流程控制语句
  • 原文地址:https://www.cnblogs.com/linjiqin/p/3425572.html
Copyright © 2011-2022 走看看