1.

How can we convert string to StringBuilder?

Answer»

The append() method can be used to convert String to StringBuilder, and the toString() method can be used to convert StringBuilder to String. Below is a Java program to convert a string array to ONE StringBuilder object using the append method.

Example: 

public CLASS StringToStringBuilder { public static void main(String ARGS[]) { String strs[] = {"Scaler", "by", "InterviewBit!"}; StringBuilder SB = new StringBuilder(); sb.append(strs[0]); sb.append(" "+strs[1]); sb.append(" "+strs[2]); System.out.println(sb.toString()); }}

Output

Scaler by InterviewBit!


Discussion

No Comment Found