fork download
  1.  
  2. class Ideone
  3. {
  4. public static void main (String[] args)
  5. {
  6. StringBuilder sb = new StringBuilder();
  7. sb.append("Ishika"); // adds a string at the end //Ishika
  8. sb.insert(2, "ach"); // adds a string or character at an index //Isachhika
  9.  
  10. System.out.println(sb);
  11. sb.delete(2,5); // deletes the substring from [start idx, end idx) // Ishika
  12. sb.deleteCharAt(4); // deletes the char present at given idx // Ishia
  13. System.out.println(sb);
  14. sb.replace(4, 5, "ka"); // Ishika
  15. System.out.println(sb);
  16. sb.reverse(); // reverses the string // akihsI
  17. sb.setCharAt(2, 'a'); // changes the char at given index // akahsI
  18. System.out.println(sb);
  19.  
  20. System.out.println(sb.charAt(4));
  21. System.out.println(sb.length());
  22. System.out.println(sb.capacity());
  23. sb.ensureCapacity(50);
  24. System.out.println(sb.capacity()); // 50
  25.  
  26. sb.delete(0,sb.length()+1);
  27. sb.append("Ishika Jain Hemant Jindal");
  28. System.out.println(sb);
  29. System.out.println(sb.capacity()); // 50
  30. sb.trimToSize();
  31. System.out.println(sb.capacity()); // 25
  32. }
  33. }
Success #stdin #stdout 0.07s 52460KB
stdin
Standard input is empty
stdout
Isachhika
Ishia
Ishika
akahsI
s
6
16
50
Ishika Jain Hemant Jindal
50
25