The Artima Developer Community
Sponsored Link

Java Buzz Forum
SubString Example from Java String Class - How To

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Javin Paul

Posts: 1090
Nickname: javinpaul
Registered: Jan, 2012

Javin Paul is Java Programmer working on Finance domain.
SubString Example from Java String Class - How To Posted: Aug 16, 2013 3:04 AM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by Javin Paul.
Original Post: SubString Example from Java String Class - How To
Feed Title: Java67
Feed URL: http://www.java67.com/feeds/posts/default?alt=rss
Feed Description: Java and technology tutorials, tips, questions for all programmers.
Latest Java Buzz Posts
Latest Java Buzz Posts by Javin Paul
Latest Posts From Java67

Advertisement
SubString in Java is a useful method from java.lang.String class, which is used to create smaller String from bigger ones. The way Substring works prior to Java 1.7, can create subtle memory leak, because both String and their substring shares same character array. Which means, if you have a big String of 200MB and created substring of 2MB from that, that could prevent 200MB String from being garbage collected. I agree this doesn't look normal and indeed was a bug, but it was like that till Java 1.6 and it's various update. One reason, which I could think, why Java designer initially thought like that, may be to save memory by sharing char array and to make, creating substring faster by just copying pointers, instead of data. Nevertheless, this was reported as bug and Oracle has fixed it, so no more substring memory leak issue in Java 7. This issue doesn't undermine important of substring method, which is one of the most important one from java.lang.String class. One thing, which is also worth remembering is that, whenever you call substring method, it return a separate String object, because String is immutable in Java. In next section we will see syntax of substring method and How to use it for practical purpose.
Read more ยป

Read: SubString Example from Java String Class - How To

Topic: Two TCKs for Eclipse โ€“ What is really in it for Open Source? Previous Topic   Next Topic Topic: Difference between Comparator and Comparable in Java - Interview Question

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use