java有用的方法



深度克隆对象

  1. 使用深度拷贝的第三方工具,比如dozer,或者apache的common lang3 中的工具包等
Mapper mapper = new DozerBeanMapper();//使用方法
Student lisi = mapper.map( 对象 , Student.class);

地址

  1. 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)

重写hashSet(需要重写hashCode和equals)

HashSet和HashMap基本使用方法

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值