白话- 那些可爱的Java 工具类

0 commons beanutils

  
      commons-beanutils
      commons-beanutils
      1.9.3
  

 User user = new User();
 BeanUtils.setProperty(user,"username","name");
 BeanUtils.setProperty(user,"password","password");
 System.out.println(JSONObject.toJSONString(user));
// map-> bean 
Map describe = BeanUtils.describe(user);
User user1 = new User();
BeanUtils.populate(user1,describe);
System.out.println(JSONObject.toJSONString(user1));

1 Collections

List l1 = Lists.list("1", "2", "3");
List l2 = Lists.list("2", "3", "4");
System.out.println(CollectionUtils.isEmpty(l1));
System.out.println(CollectionUtils.retainAll(l1, l2));
System.out.println(CollectionUtils.union(l1, l2));
System.out.println(CollectionUtils.subtract(l1, l2));
System.out.println(CollectionUtils.isEqualCollection(l1, l2));

2 stop watch

  
      com.google.guava
      guava
      21.0
  

Stopwatch stopwatch = Stopwatch.createStarted();
// 以秒打印从计时开始至现在的所用时间,向下取整
System.out.println(stopwatch.elapsed(TimeUnit.SECONDS)); // 1

你可能感兴趣的:(白话- 那些可爱的Java 工具类)