I have a string like below
12SELVASOFTWAREENGINEER................323
This string length is more than 10000
First two letter of this string is employee Id
So i can get my employee id like below
String empid = str.substring(0,2);
but this string creates the same space for original String, so memory leak will happen.
How to avoid this?
Is their any alternative or efficient way is their for getting the part of the string in java
Any help will be greatly appreciated!!!
String empid = new String(str.substring(0,2));accomplish what you want?str.substring(0, 2)returns a new string that is a substring ofstr. The new string will be only 2 characters long.substringwas addressed in Java 7. What version of Java are you using?