In this post, I will show you how to remove the characters/string from a string at a specific index. In Java, there is no such function available in String class. We have the following two alternates available StringBuilder StringBuffer Option 1 (StringBuilder) StringBuilder builder = new StringBuilder("hello to Java"); builder.delete( 5, 8 ); System.out.println( builder );// OUTPUT hello Java To remove a single character StringBuilder builder = new StringBuilder("hello to Java"); builder.deleteCharAt( 0 ); System.out.println( builder );// OUTPUT ello to Java Option 2 (StringBuffer) StringBuffer buffer = new StringBuffer ("hello to Java"); buffer .delete( 5, 8 ); System.out.println( buffer );// OUTPUT hello Java To remove a single c...
Blog about programming