Interning is making identical immutable objects hold the same reference to save memory. When s3
is interned, it is set to point to s1
from the inter pool(as it is a literal it is added there readily).
Since they have the same reference, ==
returns true.
More Related Contents:
- How to add to string number and keep string in Java?
- What is the Java string pool and how is “s” different from new String(“s”)? [duplicate]
- Questions about Java’s String pool [duplicate]
- Converting ‘ArrayList to ‘String[]’ in Java
- Why does Java’s hashCode() in String use 31 as a multiplier?
- String is immutable. What exactly is the meaning? [duplicate]
- Is there a way to get rid of accents and convert a whole string to regular letters?
- How to convert a char to a String?
- How can I replace non-printable Unicode characters in Java?
- Immutable class?
- how to convert java string to Date object [duplicate]
- How do I make my string comparison case-insensitive?
- Binary to text in Java
- Compare one String with multiple values in one expression
- Replace the last part of a string
- Format file size as MB, GB, etc [duplicate]
- Extract time from date String
- Java String Scanner input does not wait for info, moves directly to next statement. How to wait for info? [duplicate]
- String contains – ignore case [duplicate]
- Cleanest way to build an SQL string in Java
- Java: How to split a string by a number of characters?
- Creating a UUID from a string with no dashes
- String concatenation containing Arabic and Western characters
- Splitting String and put it on int array
- How can I trim beginning and ending double quotes from a string?
- Android coding with switch (String)
- Sorting ArrayList of Objects by Object attribute
- Random element from string array [closed]
- What is difference between mutable and immutable String in java
- Why does byteArray have a length of 22 instead of 20?