How to create an object in String
This article is to share with you about how to create an object in String. The editor thinks it is very practical, so I share it with you. I hope you can get something after reading this article.
Code public class StaticFinalStringTest {
Public static void main (String [] args) {String a = "x"; String x = new String ("x"); String Q = a + "x"; String p = a + new String ("x");}
}
Data parsed by javap
Compiled from "StaticFinalStringTest.java" public class com.zang.statictest.StaticFinalStringTest {public com.zang.statictest.StaticFinalStringTest (); Code: 0: aload_0 1: invokespecial # 8 / / Method java/lang/Object. "": () V 4: return
Public static void main (java.lang.String [])
Code:
0: ldc # 16 constant to Operand stack / / String x
2: astore_1 stores the reference type or returnAddress type value in the local variable 1
3: new # 18 create class instance / / class java/lang/String
6: a word length at the top of the dup copy stack
7: ldc # 16 / / String x
9: invokespecial # 20 calls the instance method / / Method java/lang/String. "": (Ljava/lang/String;) V that requires special handling
12: astore_2 stores the reference type or returnAddress type value in the local variable 2
13: new # 23 create class instance / / class java/lang/StringBuilder
16: one word length at the top of the dup copy stack
17: aload_1 loads reference type values from local variable 1
18: invokestatic # 25 calls the static method / / Method java/lang/String.valueOf: (Ljava/lang/Object;) Ljava/lang/String in the named class
21: invokespecial # 29 calls the instance method / / Method java/lang/StringBuilder. "": (Ljava/lang/String;) V that requires special handling
24: ldc # 16 constant to Operand stack / / String x
26: invokevirtual # 30 instance method of scheduling object / / Method java/lang/StringBuilder.append: (Ljava/lang/String;) Ljava/lang/StringBuilder
29: invokevirtual # 34 instance method of scheduling object / / Method java/lang/StringBuilder.toString: () Ljava/lang/String
32: astore_3 stores the reference type or returnAddress type value in the local variable 3
33: new # 23 create class instance / / class java/lang/StringBuilder
36: a word length at the top of the dup copy stack
37: aload_1 loads reference type values from local variable 1
38: invokestatic # 25 calls the static method / / Method java/lang/String.valueOf: (Ljava/lang/Object;) Ljava/lang/String in the named class
41: invokespecial # 29 calls the instance method / / Method java/lang/StringBuilder. "": (Ljava/lang/String;) V that requires special handling
44: new # 18 create class instance / / class java/lang/String
47: one word length at the top of the dup copy stack
48: ldc # 16 constant to Operand stack / / String x
50: invokespecial # 20 calls the instance method / / Method java/lang/String. "": (Ljava/lang/String;) V that requires special handling
53: instance method of invokevirtual # 30 scheduling object / / Method java/lang/StringBuilder.append: (Ljava/lang/String;) Ljava/lang/StringBuilder
56: invokevirtual # 34 instance method of scheduling object / / Method java/lang/StringBuilder.toString: () Ljava/lang/String
59: astore 4 will store the reference type or returnAddress type value in a local variable
61: return
}
This is how to create an object in String. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.