1.将一个对象中属性拷贝到另一个对象中
PropertyUtils.copyProperties(f, r);//其中f,r为对象,会将rf中的属性相同的,从r,拷贝到f
2.统计一段程序运行时间
法1:
long begin = System.currentTimeMillis();
。。。
。。。
long used = System.currentTimeMillis()-begin;
法2:
StopWatch stopWatch = new StopWatch();
stopWatch.start();
。。。
。。。
stopWatch.stop();
LOGGER.info("清理redis key=" +key + ",field="+ field +" 耗时:"+ stopWatch.getTime());
3.对象判空
1)Map集合是否为空或者size=0
MapUtils.isEmpty(resultItemAverageMap)
2)List集合是否为空或者size=0
Collections.isEmpty(list);
3)字符串是否为空,或者为空串
StringUtils.isEmpty(“123”)
4.字符串切分
StringTokenizer st = new StringTokenizer(ids, ",");
while (st.hasMoreElements()) {
String value = st.nextToken();
String index[] = value.split("_");
PilSuggest pilSuggest = new PilSuggest();
pilSuggest.setProductCode(Long.valueOf(index[0]));
pilSuggest.setSuggestType(String.valueOf(index[1]));
list.add(pilSuggest);
}