Home > Java > javaTutorial > body text

String intern method

巴扎黑
Release: 2016-12-02 09:16:27
Original
1433 people have browsed it

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);
Copy after login

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.

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