深度克隆对象
- 使用深度拷贝的第三方工具,比如dozer,或者apache的common lang3 中的工具包等
Mapper mapper = new DozerBeanMapper();//使用方法
Student lisi = mapper.map( 对象 , Student.class);
- BeanUtils.copyProperties(src,target)
地址
有效数字
//保留三位有效数字
double aa=1;
System.out.println(String.format("%.3f", aa));
//数学计数法
System.out.println(1e-6==0.000001);//0.000001 1e+4==10000
格式化时间
//获取现在的时间
Date date = new Date();
String str = "yyy-MM-dd HH:mm:ss";
SimpleDateFormat sdf = new SimpleDateFormat(str);
System.out.println(sdf.format(date));
判断 数字字母
char ch='4';
//判断字符是不是数字
System.out.println(Character.isDigit( ch));
ch='a';
//判断字符是不是字母
System.out.println(Character.isLetter( ch));
//判断字符是不是字母和数字
System.out.println(Character.isLetterOrDigit( ch ));
String s="asSad";
//字符串转化为小写 大写
System.out.println(s.toLowerCase()+" " +s.toUpperCase());
数字各位相加
int x=12345; int y=0;
while(x>0)
{y+=x%10;x/=10;}//数字各为数字相加 System.out.println(x+" "+y);
随机数的用法
(int) (Math.random() * 100 + 1)