xxxxxxxxxx
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("string");
System.out.println("String = " + stringBuilder.toString());
xxxxxxxxxx
// 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
xxxxxxxxxx
//StringBuilder in Java represents a mutable sequence of characters.
// Example(1) Create StringBuilder without Arguments
StringBuilder name = new StringBuilder(); // Create a StringBuilder object
// Example(2) Create StringBuilder with Arguments
StringBuilder name = new StringBuilder("Computer System");
// Example(3) Change from String Object to StringBuilder Object
String name = "jack"; // String Object
StringBuilder name2 = new StringBuilder(name); // add String Object in StringBuilder Constructor
System.out.println(name2); // print StringBuilder Object
System.out.println(name2.toString); // print String Object
xxxxxxxxxx
StringBuilder objects are like String objects, except that they can be modified
xxxxxxxxxx
if (CollectionUtils.isEmpty(primaryPathList)) {
final String COMMON = "Customer Hierarchy is mandatory field";
if (salesChannelCode.equals(SalesChannelType.HEB_TO_YOU)) {
return Optional.of(COMMON + " for HebToYou.");
} else {
return Optional.of(COMMON + ".");
}
}