Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

stringbuilder java

// Overuse of String concatenation can build large numbers of String objects
// a huge drain on performance and memory, hence code below is avoided
String firstName = "Chris";
String lastName = "Wells";
String fullName = firstName + " " + lastName;

// StringBuilder
// provides dynamic string manipulation without performance overhead of String class
StringBuilder nameBuffer = new StringBuilder("John");
nameBuffer.append(" ");
nameBuffer.append("Richard");
System.out.println(nameBuffer.toString());  //must convert to Strings before can be printed
 
PREVIOUS NEXT
Tagged: #stringbuilder #java
ADD COMMENT
Topic
Name
3+4 =