How to remove the last character from StringBuilder in Java

1 Answer

0 votes
public class MyClass {
    public static void main(String args[]) {
        StringBuilder sb = new StringBuilder("java c c++ c# python");
        
        int len = sb.length();
        
        if (len > 0) {
            sb.deleteCharAt(len - 1);
        }
        
        System.out.println(sb);
    }
}
 
  
  
  
/*
run:
       
java c c++ c# pytho
    
*/

 



answered Oct 5, 2023 by avibootz

Related questions

...