The
append()method of the
StringBuilderclass accepts a String value and adds it to the currentobject.
Convert the string value to a StringBuilder object -Get the string value.
Append using theappend()method to get the string to the StringBuilder.
In the following Java program, we convert an array of strings into a single StringBuilder object.
Real-time demonstration
public class StringToStringBuilder { public static void main(String args[]) { String strs[] = {"Arshad", "Althamas", "Johar", "Javed", "Raju", "Krishna" }; StringBuilder sb = new StringBuilder(); sb.append(strs[0]); sb.append(" "+strs[1]); sb.append(" "+strs[2]); sb.append(" "+strs[3]); sb.append(" "+strs[4]); sb.append(" "+strs[5]); System.out.println(sb.toString()); } }
Arshad Althamas Johar Javed Raju Krishna
The above is the detailed content of Convert string to StringBuilder in Java. For more information, please follow other related articles on the PHP Chinese website!