java常用类

java常用类    (反复强调自己是纯爷们儿,那就是傻冒!!!               哈哈哈)

 

 

 

基本数据类型的包装类(Wrapper Class)   

 

代码示例    (Integer)

package cn.array2;

public class WrapperClass {
    public static void main(String[] args) {
        Integer a=new Integer(1000);    //把1000包装成一个对象
        
        System.out.println(Integer.MAX_VALUE); //最大值 2147483647
        System.out.println(Integer.toHexString(a));//转换为16进制
        
        Integer a2=Integer.parseInt("2222");    //字符串转数字 方式一
        Integer b=new Integer("222");            //字符串转数字 方式二
        
        System.out.println(a2);
        System.out.println(b+20);
        System.out.println(a2.intValue());      //intValue()直接转
        
        String str=234+"";                      //数字转字符串
        System.out.println(str);

    }
}

自动装箱与拆箱(auto-boxing & unboxing)

 

 

 代码示例

package cn.array2;
/*
 * 测试自动装箱与拆箱
 * */
public class Test02 {
    public static void main(String[] args) {
//        Integer a=new Integer(1000);
        Integer a=1000;  //JDk5.0之后,有了自动装箱,不用写new Integer(1000),直接写1000
        Integer b=10000;  //装箱 ,b是一个对象
        
        int c=new Integer(1000); //编译器改进:new Integer(1000).intValue();
        
        System.out.println(c);      
        
        
        Integer s=1000;
        Integer s1=1000;
        
        System.out.println(s==s1);   //两个对象比较,false
        System.out.println(s.equals(s1)); //值比较 ,true
        
        Integer d=-128;
        Integer d1=-128;
        
        System.out.println(d==d1);        //两个对象比较,true,涉及缓存,[-128,127]之间的数,仍然当作基本数据类型来处理。
        System.out.println(d.equals(d1));  //值比较 ,true
        
        
    }
}

 

 缓存问题(提高效率)

时间处理相关类

 

 Date时间类

示例

package cn.date;

import java.util.Date;

public class Test01 {
    public static void main(String[] args) {
        Date d=new Date();
        
        long t=System.currentTimeMillis();     //1563433917990
        System.out.println(t);
        
        Date d2=new Date(1000);
        System.out.println(d);                            //打印当前时间 Thu Jul 18 15:11:57 CST 2019
         
        System.out.println(d2.toGMTString());          //被废弃了   1 Jan 1970 00:00:01 GMT
        
        System.out.println(d2.getTime());              //1000
        
        System.out.println(d.getTime()<d2.getTime());   //比较  false
    }
}

 

posted on 2019-07-18 15:18  Mentality  阅读(160)  评论(0编辑  收藏  举报