Learn Selenium and Java for Selenium

Sunday, 3 June 2018

Strings in Java Part3

How are strings stored in memory?

As we know that string can be created via 2 ways i.e by using sting literal (implicit) or by creating a string object using a new keyword.

STRING POOL

  • Whenever a string is created via literal, the value is stored in special memory string pool.
  • JVM looks if there is value is present on the string pool, the same value is allocated to the new string literal
  • String pool will increase the memory efficiency and better performance

String s1 = "Hello";             // String literal

String s2 = "Hello";             // String literal

String s3 = s1;                   // same reference


STRING HEAP
  • Whenever a string is created via new keyword, the value is stored in string heap.
  • Each string object in a heap has its own storage
  • There is no sharing of storage in heap even if two string have same content
String s4 = new String("Hello");  // String object

String s5 = new String("Hello");  // String object













Related Posts:

  • Strings in Java : Part 4 String Methods As we know that string class has variety of methods for String manipulation. We would be explaining the mostly used methods available… Read More
  • Strings in Java : Part 5 String Methods Continuing with commonly used method in the stings we are covering here charAt()  method is more detailed manner. String char… Read More
  • GIT in Practical World GIT in Practical World We have discussed about meaning of different GIT commands. Now biggest challenge is how exactly GIT is being used in ou… Read More
  • What is JIRA? We have been hearing about JIRA a lot these day. Aren’t we? So, let us discuss some key pointers on JIRA today. JIRA is a project managemen… Read More
  • GIT Introduction GIT Introduction Any automation testing project, we need to develop around 100 + testcases in the limited span of time. It is impossible if you… Read More

0 comments:

Post a Comment

Popular Posts

Recent Posts



Newsletter

Join our newsletter to get secret tips directly in your inbox!


*We Hate Spam!

Powered by Blogger.