JAVA - Little knowledge
Integer is the wrapper class of int , int is a basic data type of java
Integer variables must be instantiated before they can be used, while int variables do not require
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
The default value of Integer is null, int The default value is 0
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
Integer is a wrapper class for int, which is a basic data type of java
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)
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
Number—>Convert to—->String: String a = “” num;
String type cannot use str[i], but use str.charAt(i)
Get the substring and determine whether is equal to needle
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
##
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)
4. Stack
Related recommendations:
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!