Java String interning

0 votes

Can someone explain, what is String Interning in Java and whats its purpose?

Oct 25, 2018 in Java by 93.lynn
• 1,620 points
105 views

1 answer to this question.

0 votes

The String.intern() method of Java Strings ensures that all strings contain the same content and share the same memory. 

For example, if you have a list of fruits, in which apple occurs 100 times, then with the help of String Interning you can ensure that only one apple is an actually allocated to the memory.

It's an important Java function that helps a lot in saving up the memory space.

For more details, you can refer here:​ http://docs.oracle.com/javase/7/docs/api/java/lang/String.html#intern()

answered Oct 25, 2018 by geek.erkami
• 2,680 points

Related Questions In Java

0 votes
2 answers

How can I convert a String variable to a primitive int in Java

 Here are two ways illustrating this: Integer x ...READ MORE

answered Aug 20, 2019 in Java by Sirajul
• 55,300 points
442 views
0 votes
2 answers

Integer to String conversion in java

We can do this in 2 ways: String ...READ MORE

answered Jul 27, 2018 in Java by samarth295
• 2,190 points
165 views
0 votes
3 answers

String to Double conversion in java

Double temp = Double.valueOf(str); number = temp.doubleValue(); READ MORE

answered Sep 10, 2018 in Java by Sushmita
• 6,890 points
142 views
0 votes
4 answers

Remove extra spaces from string in java

import java.util.regex.Matcher; import java.util.regex.Pattern; String pattern="[\\s]"; String replace=""; part="name=john age=13 year=2001"; Pattern ...READ MORE

answered Sep 10, 2018 in Java by Parth
• 4,630 points
451 views
0 votes
2 answers

what is the best way to convert an ArrayList to a String

You could probably use the Joiner class ...READ MORE

answered Aug 19, 2019 in Java by Sirajul
• 55,300 points
144 views
0 votes
1 answer

Default Object.toString() in hashcode

Well, the hash code object is the ...READ MORE

answered Oct 30, 2018 in Java by code.reaper12
• 3,470 points
132 views
+5 votes
3 answers

How to execute a python file with few arguments in java?

You can use Java Runtime.exec() to run python script, ...READ MORE

answered Mar 27, 2018 in Java by DragonLord999
• 8,420 points

edited Nov 6, 2018 by Omkar 26,472 views
0 votes
1 answer

How to handle drop downs using Selenium WebDriver in Java

First, find an XPath which will return ...READ MORE

answered Mar 27, 2018 in Selenium by nsv999
• 5,510 points
3,950 views
0 votes
2 answers

How to convert ArrayList<String> to String[] in Java

Try this:  String[] strArray = arrayList.toArray(new Str ...READ MORE

answered Aug 21, 2019 in Java by Sirajul
• 55,300 points
149 views
0 votes
2 answers

Java enum lookup using a String

Check this...Java Enum in details READ MORE

answered Dec 4, 2018 in Java by allenvarna
• 520 points
143 views