StringBuilder
StringBuilder changes text without creating many strings. Use it in loops.
Example
public class Main {
public static void main(String[] args) {
StringBuilder sb = new StringBuilder();
for (int i = 1; i <= 3; i++) sb.append(i).append(",");
sb.setLength(sb.length() - 1);
System.out.println(sb.reverse());
}
}Result
3,2,1
Exercise
Add text.
sb.("x")
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.