Home  >  Article  >  Java  >  String intern method

String intern method

巴扎黑
巴扎黑Original
2016-12-02 09:16:271400browse

String a = "ab";
String b = new String("ab");
System.out.println(a == b);
System.out.println(a.equals(b));
System.out.println(b.intern() == a);
System.out.println(a.intern() == b);

Print result:
false
true
true
false

new String will not look for the existing string in the String constant. The string.intern() method finds equal strings in the character constant pool.

Statement:
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