Home > Java > javaTutorial > Summary of little knowledge that may be omitted in JAVA

Summary of little knowledge that may be omitted in JAVA

php是最好的语言
Release: 2018-08-10 14:16:33
Original
1447 people have browsed it

JAVA - Little knowledge

1. The difference between int and Integer

  1. Integer is the wrapper class of int , int is a basic data type of java

  2. Integer variables must be instantiated before they can be used, while int variables do not require

  3. Integer It is actually a reference to the object. When new an Integer, a pointer is actually generated pointing to the object; while int directly stores the data value

  4. The default value of Integer is null, int The default value is 0

  5. Since 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(100);
    Integer j = new Integer(100);
    System.out.print(i == j); //false
Copy after login
  1. Integer is a wrapper class for int, which is a basic data type of java

  2. Integer variable When comparing with int variables, as long as the values ​​​​of the two variables are equal, the result is true (because when the packaging class Integer is compared with the basic data type int, java will automatically unpack it into int, and then compare it. In fact, it becomes Comparison of two int variables)

  3. When the Integer variable generated by non-new is compared with the variable generated by new Integer(), the result is false. (Because the Integer variable generated by non-new points to an object in the Java constant pool, and the variable generated by new Integer() points to a newly created object in the heap, the addresses in the memory of the two are different)

    Integer i = new Integer(100);
    Integer j = 100;
    System.out.print(i == j); //false
Copy after login

2. String type

  1. Number—>Convert to—->String: String a = “” num;

  2. String type cannot use str[i], but use str.charAt(i)

  3. ##haystack.substring(i,i l2).equals(needle) //

    Get the substring and determine whether is equal to needle

  4. ##return new StringBuffer(s).reverse().toString(); //Reverse conversion String
    1. #StringBuffer The operation on the string itself is superior to String in memory and is thread-safe.
    2. Conversion between StringBuffer and String:
    3.           String s = “abc”; ​ ​ ​ StringBuffer sb1 = new StringBuffer(“123”); ​ ​ ​ StringBuffer sb2 = new StringBuffer(s); ​ ​ ​ //Convert String to StringBuffer String s1 = sb1.toString(); //Convert StringBuffer to String

    3. Base conversion

    java.lang There are functions for base conversion in the .Integer API package:
  1. These three functions can convert decimal integers into binary, 16, and octal numbers


    ##

        public static String toBinaryString(int i)    // String a = Integer.toBinaryString(n)
        public static String toHexString(int i)     // String a = Integer.toHexString(n)
        public static String toOctalString(int i)     // String a = Integer.toOctalString(n)
    Copy after login
    Stack st = new Stack();

    4. Stack

    Declaration:

    Related recommendations: Summary of little knowledge that may be omitted in JAVA

    Summary of common problems in development-JAVA primary introductory video tutorial

    Summary analysis of Java basic knowledge

    The above is the detailed content of Summary of little knowledge that may be omitted in JAVA. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template