Remove a character from a string
Anonym
Use replace() to remove all instances of a character. originalString.replace(Character.toString(charToRemove), "") Use substring() or StringBuilder if you want to remove a character at a specific position. int indexOfCharToRemove=4; original.substring(0,indexOfCharToRemove)+original.substring(indexOfCharToRemove+1) StringBuilder newString = new StringBuilder(original); newString.deleteCharAt(indexToRemove); Use a loop if you need more control over the removal process or want to filter out certain characters. StringBuilder newString = new StringBuilder(); for(char c: original.toCharArray()) { if(c!=charToRemove) newString.appendd(c); }