Summary of small knowledge that will be overlooked in Java

Source: Internet
Author: User
Tags wrapper

JAVA-Little knowledge

1. The difference between int and integer

    1. Integer is the wrapper class for int, and int is a basic data type of Java

    2. An integer variable must be instantiated before it can be used, and the int variable does not need

    3. An integer is actually a reference to an object, and when new is an integer, it actually generates a pointer to the object, while int stores the data value directly

    4. The default value for integer is the default value of Null,int is 0

    5. Because the integer variable is actually a reference to an integer object, the two integer variables generated by new are never equal (because new generates two objects with different memory addresses).

    Integer i = new integer (+);    Integer j = new Integer (+);    System.out.print (i = = j); False
    1. Integer is the wrapper class for int, and int is a basic data type of Java

    2. When an integer variable is compared to an int variable, the result is true if the value of the two variable is equal (because the wrapper class integer and the base data type int are compared, the Java is automatically wrapped to int and then compared, and actually becomes a comparison of two int variables)

    3. The result is false when a non-new generated integer variable is compared to a variable generated by the new Integer (). (Because a non-new integer variable points to an object in a Java constant pool, the new Integer () generates a variable that points to the new object in the heap, and the address in memory is different)

    Integer i = new integer (+);    Integer j = +;    System.out.print (i = = j); False

2. String type

    1. Digital---convert to-->string:string a = "" +num;

    2. String type cannot be used with str[i], but Str.charat (i)

    3. Haystack.substring (I,I+L2). Equals (needle)// takes a substring and determines whether it equals needle

    4. return new StringBuffer (s). Reverse (). toString (); Reverse Convert string

      1. It is thread-safe for StringBuffer to manipulate the string itself in memory that is better than string.

      2. Conversion between StringBuffer and string:

        String s = "abc"; StringBuffer sb1 = new StringBuffer ("123"); StringBuffer SB2 = new StringBuffer (s); The string is converted to StringBuffer string S1 = sb1.tostring (); StringBuffer Convert to String

3. Binary conversion

    1. Java.lang.Integer This API package has the function of the binary conversion:
      These 3 functions can convert decimal integers to 26 or 16, octal numbers

    public static string tobinarystring (int i)    //String a = Integer.tobinarystring (n) public    static string Tohexstri ng (int i)     //String a = Integer.tohexstring (n) public    static string tooctalstring (int i)     //String a = Integer . tooctalstring (N)

Stack st = new stack ();

4. Stack

    1. Statement:

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.