集合工具类的使用
关于集合工具类的使用实例
public static void main(String[] args) { List<String> list1 = new ArrayList<>(); if(CollectionUtils.isNotEmpty(list1)){ System.out.println("list1不为空"); }else{ System.out.println("list1为空"); } List<String> list2 = null; if(CollectionUtils.isNotEmpty(list2)){ System.out.println("list2不为空"); }else{ System.out.println("list2为空"); } Map map1 = new HashMap(); map1.put("test1","张三1"); map1.put("test2",""); map1.put("test3",null); map1.put("test4","张三4"); Map map2 = null; String test1 = MapUtils.getString(map1,"test1"); String test2 = MapUtils.getString(map1,"test2"); String test3 = MapUtils.getString(map1,"test3","MAP1为空取默认值"); String testnull = MapUtils.getString(map2,"testnull","MAP2为空取默认值"); String testnull2 = MapUtils.getString(map2,"testnull", StringUtils.EMPTY); System.out.println("MAP1为空的情况下.test1=="+test1); System.out.println("MAP1为空的情况下.test2=="+test2); System.out.println("MAP1为空的情况下.test3=="+test3); System.out.println("MAP2为空的情况下.testnull=="+testnull); System.out.println("MAP2为空的情况下.testnull=="+testnull); System.out.println("MAP2为空的情况下.testnull2=="+testnull2); }