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,560 points
38 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,320 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 in Java by Sirajul
• 25,580 points
133 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
71 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,880 points
46 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 parth295
• 4,620 points
86 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 in Java by Sirajul
• 25,580 points
59 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,450 points
31 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,380 points

edited Nov 6, 2018 by Omkar 8,167 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,090 points
1,990 views
0 votes
2 answers

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

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

answered Aug 21 in Java by Sirajul
• 25,580 points
68 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
70 views