java 常用备忘录

 /*
  * 基本类型转换
  * 精度低的自动转精度高的
  * 1) byte,short,char->int->long->float->double
  * 2) byte,short,char之前不会互相转换,他们三者在计算时首先会转换为int类型
  * 注意:Java中可以将int型数值常量直接赋值给相应低级的byte,short,char型变量,而不需要进行强制类型转换,只要不超出变量的数值范围.
  *
  */
 
 /*
  * 基本类型转换
  * 精度高的向精度低的转换
  * int to byte: byteAbc = intAbc.byteValue();
  * int to short: shortAbc = intAbc.shortValue();
  *
  * long to byte: byteAbc = longAbc.byteValue();
  * long to short: shortAbc = longAbc.shortValue();
  * long to int: intAbc = longAbc.intValue();
  *
  * float to byte: byteAbc = floatAbc.byteValue();
  * float to short: shortAbc = floatAbc.shortValue();
  * float to int: intAbc = floatAbc.intValue();
  * float to long: longAbc = floatAbc.longValue();
  *
  * double to byte: byteAbc = doubleAbc.byteValue();
  * double to short: shoutAbc = doubleAbc.shortValue();
  * double to int: intAbc = doubleAbc.intValue();
  * double to long: longAbc = doubleAbclongValue();
  * double to float: floatAbc = doubleAbc.floatValue();
  */
 
 /*
  * 基本类型转换成包装类
  * 通过包装类的构造器来new出一个新的类类型的变量
  * int to Integer: Integer a = new Integer(2);
  *
  *
  */
 
 /*
  * 包装类向基本数据类型转换
  * 通过类包装器来转换
  * Integer to int: intAbc = integerAbc.intValue();
  *
  *
  */
 
 /*
  * string转换成基本数据类型和包装类
  *
  * string to char: charAbc = stringAbc.charAt(int index); //index表示字符串的第几个字符,从0开始
  *
  * string to int: intAbc = Integer.parseInt(stringAbc);  
  * string to Integer: integerAbc = new Integer(stringAbc);  //Integer.valueOf(stringAbc);
  * 
  * string to long: longAbc = Long.parseLong(stringAbc);  
  * string to Long: longAbc = new Long(stringAbc);    //Long.valueOf(stringAbc);
  *
  * string to float: floatAbc = Float.parseFloat(stringAbc);  
  * string to Float: floatAbc = new Float(stringAbc);   //Float.valueOf(stringAbc);
  *
  * string to double:doubleAbc = Double.parseDouble(stringAbc);
  * string to Double:doubleAbc = new Double(stringAbc);    //Double.valueOf(stringAbc);
  *
  * 注意:parse()和valueOf()的区别
  * 比如说parseInt()就是把String类型转化为int类型
  * 比如说 Integer.valueOf() 是把String类型转化为Integer类型(注意:是Integer类型,而不是int类型,int类型是表示数字的简单类型,Integer类型是一个引用的复杂类型)
  */
 
 /*
  * to string
  * String.valueOf(intAbc/longAbc...),Stirng.format(),Object.toStirng();
  */
 
 /*
  * string to BigDecimal:
  * bigDecimalAbc = new BigDecimal(stringAbc);
  * bigDecimalAbc = BigDecimal.valueOf(Double.valueOf(stringAbc));
  *
  * BigDecimal to 基本数据类型依次是:byteValueExact(),shortValueExact(),intValue()/ intValueExact(),longValue()/longValueExact() ,floatValue() ,doubleValue();
  *
  */
 
 /*
  * string to date
  * java.text.SimpleDateFormat formatter = new java.text.SimpleDateFormat( "yyyy-MM-dd HH:mm");
       formatter.format(new Date());
       //String fmt = "yyyy-MM-dd hh:mm";
    //SimpleDateFormat sdf = new SimpleDateFormat(fmt);
    //sdf.parse(new Date());
  *
  */
 
 /*
  * ==与equals的区别
  * ==用于比较引用和比较基本数据类型时具有不同的功能:
  比较基本数据类型,如果两个值相同,则结果为true
  而在比较引用时,如果引用指向内存中的同一对象,结果为true
  equals 方法(是String类从它的超类Object中继承的)被用来检测两个对象是否相等,即两个对象的内容是否相等。
  *
  */
 
 /*
  * 字符串的拆分、分割
  *
  */
 
 /*
  * 字符串拆分成字符串数组
  * if(associatedCheckMoreOldStr.length()>0){
      String[] tmp = associatedCheckMoreOldStr.split("_");
      associatedCheckMoreOld = new String[tmp.length];
      for(int i =0;i <tmp.length;i++){
       associatedCheckMoreOld[i] = tmp[i];
      }
     }
  *
  */
 
 /*
  * 迭代list
  *
  *  public void diedai(List l){
     Iterator iter = l.iterator();
     while(iter.hasNext()){
       Object[] o = (Object[]) iter.next();
       for(int i=0;i<o.length;i++){
          System.out.println("-----"+i+":"+o[i]);
      }
     }
   }
  *
  */
 
 /* 分页
  *
  *  public void paging(Long zong,int kuai){
  pageCount=(zong+kuai-1)/kuai;
  if(page>pageCount){
   page=pageCount.intValue();
  }
  if(pageCount>=page && page>0){
   start=(page-1)*kuai+1;
   end = start+kuai-1;
  }
  if(pageCount==0){
   start=1;
   end = start+kuai-1;
  }
 }
  */
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值