java - Extracting the initial characters from a string in one go -


please advise below code extract first 4 characters string shown below..

string external = ak.getreference();     string s= external.substring(0,4); 

can wrap 1 no string s need created , string external have 4 initial characters in 1 go

well, can chain method calls...

string s = ak.getreference().substring(0,4); 

... doesn't mean string won't created, starting java 7u6 substring() method return new string object freshly allocated char[] (see post). you're eliminating intermediate local variable, that's all.


Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

java - Copying object fields -

c++ - Clear the memory after returning a vector in a function -