Automatic entry boxes, large data operation, Arrays, class

 

The basic string data type conversion three kinds:

① double quotation marks ""  + basic types

② call  valueOf  method

③ call  toString  method

 

public  static  void main (String [] args) {
         // string -> basic data types 
        String STR = "12 is"; // string must be an integer 
        int NUM = the Integer.parseInt (STR); 
        the System.out .println (NUM + 1'd );
         double num2 = Double.parseDouble (STR); 
        System.out.println (num2); 
        // the basic types -> a first string substantially double quotes + type 
        System.out.println ( "" 12 + 1 + );
         // the int type String a second transfer method valueOf 
        String S1 = String.valueOf (88 ); 
        String S2 = String.valueOf (1.2 ); 
        System.out.println (S2+1 );
         // third method calls toString 
        String Integer.toString S3 = (99 ); 
        System.out.println (S3 + 1 );         
    }

The basic types and object conversion

public  static  void main (String [] args) {
         // basic data types -> Packaging type object
         // 1. 
        Integer in = new new Integer (123 ); 
        Integer IN2 = new new Integer ( "456" );
         // 2. 
        Integer.valueOf IN3 = Integer (789 ); 
        Integer IN4 = Integer.valueOf ( "147" );
         // package type object -> base data type 
        int I1 = in.intValue ();
         int I2 = in2.intValue () ; 
    }

 

Chapter 1 Arrays class

This class contains various methods for manipulating arrays (such as sorting and searching). Note that if the specified array reference is null, the access method in this class will throw null pointer exception NullPointerException .

Arrays Array class is a utility class, Arrays is an array, the array is not a class

 

 

In addition to other integer and character of initial capital letters!

    sort method for sorting (element values ordered from small to large) specified elements in the array
 // source array elements arr {1,5,9,3,7}, after sorted array elements arr {1, } 3,5, 7,9 
int [] = {1,5,9,3,7 ARR }; 
Arrays.sort (ARR); 
    toString method to return the specified string array element content 
int [] ARR 1,5,9,3,7 {= }; 
String STR = of Arrays.toString (ARR); // STR value [. 1,. 3,. 5,. 7,. 9] 
    binarySearch method, the specified array, to look location of a given element value occurs. If no inquiries to the return position is - (this value should be in the position) -1. Requirements The array must be ordered array.
int [] ARR = {1,3,4,5,6 };
 int index = Arrays.binarySearch (ARR,. 4); // index value 2 
int index2 = Arrasy.binarySearch (ARR, 2); // index2 is -2

  Big data computing

BigInteger is encapsulated in the class, call the constructor on the line

Package com.oracle.demo02; 

Import java.math.BigDecimal;
 Import java.math.BigInteger; 

public  class Demo07 {
 public  static  void main (String [] args) {
     // the computer is binary, lose precision in the calculation 
    System .out.println (0.09 + 0.01 ); 
    System.out.println ( 1.0 - 0.32 ); 
    System.out.println ( 1.015 * 100 ); 
    System.out.println ( 1.301 / 100 );
     // with the operation BigDecimal 
    BigDecimal BD1 = new new   the BigDecimal ( "0.09" ); 
    the BigDecimal BD2 = new new  BigDecimal("0.01");
    System.out.println(bd1.add(bd2));//
    BigDecimal bd3=new  BigDecimal("1.0");
    BigDecimal bd4=new  BigDecimal("0.32");
    System.out.println(bd3.subtract(bd4));//
    BigDecimal bd5=new  BigDecimal("1.015");
    BigDecimal bd6=new  BigDecimal("100");
    System.out.println(bd5.multiply(bd6));//
    BigDecimal bd7=new  BigDecimal("1.301");
    BigDecimal bd8=new  BigDecimal("100");
    System.out.println(bd7.divide(bd8,2,BigDecimal.ROUND_FLOOR));//

}
}
package com.oracle.demo02;

import java.math.BigInteger;

public class Demo06 {
public static void main(String[] args) {
    BigInteger in1=new BigInteger("10000000000000000000000000");
    BigInteger in2=new BigInteger("10000000000000000000000000");
    System.out.println(in1.add(in2));//
    System.out.println(in1.subtract(in2));//
    System.out.println(in1.multiply(in2));//
    System.out.println(in1.divide(in2));//

}
}

 

Guess you like

Origin www.cnblogs.com/pandam/p/10968712.html