java学习day07

2018.6.11
1.object
所有类的父类
toString 打印对象的地址值
hashCode 对象的存储位置的算法
equals 比较的是内存地址,==比的是值。
对于==,如果作用于基本数据类型的变量,则直接比较其存储的 “值”是否相等;如果作用于引用类型的变量,则比较的是所指向的对象的地址
对于equals方法,注意:equals方法不能作用于基本数据类型的变量; 如果没有对equals方法进行重写,则比较的是引用类型的变量所指向的对象的地址; 诸如String、Date等类对equals方法进行了重写的话,比较的是所指向的对象的内容。
instanceof 查看一个对象是否是另一个对象的实例。


2.String是引用类型的变量。

  byte[] bytes = "abc".getBytes();
  String str = new String(bytes);
  String concat(String str)  //用于连接两个字符串
  String trim()
   //去除字符串头尾空格  
  int compareTo(String str)
  //按字典顺序比较两个字符串
  string substring(int i)     //截取字符串中的字符或字符串
  replace(old char,new char)

3.StringBuffer
对字符串拼接,不会每次都产生新的字符串
是线程安全的可变字符序列

   append();insert();delete(int start,int end);deleteCharAt(String str);replace(int start,int end,String str);reverse();substring(int start);substring(int start,int end);

4.Arrays
针对数组进行操作的工具类
toString(int[] a);sort(int[] a);int binarySearch(int[] a,int key);


5.基本类型包装类
在对象中定义更多的功能方法操作该数据。
常用的操作之一:用于基本数据类型与字符串之间的转换。

Byte,Short,Integer,Long,Float,Double,Character,Boolean


6.Integer

  int –> String:直接相加空字符串

   String –> intpublic static int parseInt(String s)

   toBinaryString(int i)  //转换为二进制  toOctalString  toHexString
   public static int parseInt(String s,int radix)//其他进制到十进制

7.BigInteger
可以让超过Integer范围内的数据进行运算
构造方法:public BigInteger(String val)

     add,subtract,multiply
      BigInteget[] divideAndRemainder(BigInteger val)

8.BigDecimal
float,double容易丢失精度。用来精确的计算浮点数
构造函数

    BigDecimal(String val)
    BigDecimal(int val)
  add,subtract,divide,multiply

9.System

  System.in  //从键盘获得值
  System.currentTimeMills()  //获取当前微秒数

10.Date

  构造方法
  Data()    Date(long date)
  成员方法
  long getTime()
  void setTime(long time)
  代码:
    (1)Date date = new Date();
     System.out.println(date);
    (2)long time = System.currentTimeMillis();
           Date date = new Date(time);
           System.out.println(date);
    (3)Date date = new Date();
       System.out.println(date.getTime());//输出毫秒值

11.DateFormat
是日期/时间格式化子类的抽象,解析日期或日期。
是抽象类,所以使用其子类SimpleDateFormat


12.SimpleDateFormat

  构造方法
  SimpleDateFormat()
  SimpleDateFormat(String pattern)
  成员方法
  public final String format(Date date)
  public Date parse(String source)  //解析时间格式
  代码:
    SimpleDateFormat sdf1=new SimpleDateFormat("yyyy/MM/dd HH:mm"); 
        SimpleDateFormat sdf2=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        System.out.println(sdf1.format(new Date()));
        System.out.println(sdf2.format(new Date()));
        解析字符串:
        String dateStr = "2018-06-11 17:20:19" ;
        //将字符串转成date   时间对象
        SimpleDateFormat sd = new  SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        //解析时间格式的字符串   date
        Date date = sd.parse(dateStr);
        System.out.println(date);

13.Random

  Random r = new Random();
  r.nextDouble()//生产0-1之间的小数
  (int)(r.nextDouble()*10)+1   //1-10

14.Math

   public static int abs(int a)                 //绝对值
   public static double ceil(double a)          //进位
   public static double floor(double a)         //进位
   public static double pow(double a,double b)  //几次方
   public static double random()                //随机数
   public static int round(float a)             //最接近的整数
   public static double sqrt(double a)          //开方

猜你喜欢

转载自blog.csdn.net/qq_32539825/article/details/80659679