java各种小工具代码

1.数组转换成List

import java.util.Arrays;

Arrays.asList(Object[] obj);

2.判断一个String型是否有值

import org.springframework.util.StringUtils;

if (StringUtils.hasText(str))

3.判断一个List是否有值

import org.springframework.util.CollectionUtils;

if(CollectionUtils.isEmpty(collection))

4.MD5加密字符串

MD5 md5= new MD5();
encodeString = md5Util.getMD5ofStr(str);

 5.生成随即数

import org.apache.commons.lang.math.RandomUtils;

RandomUtils.nextLong();

 6.生成小于32位任意长度字符串

/** 32位 */
MD5 md5=new MD5();
md5.getMD5ofStr(String.valueOf(RandomUtils.nextLong()));
/** 16位 */
MD5 md5=new MD5();
md5.getMD5ofStr(String.valueOf(RandomUtils.nextLong())).substring(0, 16);

7.List转换成数组

list.toArray(new String[list.size()])
 

猜你喜欢

转载自286.iteye.com/blog/1175163