如何从给定的string中删除一个子string?
有没有一种简单的方法来从Java中给定的string中删除子string?
例如:“Hello World!” ,去掉“o” – >“Hell Wrld!”
你可以很容易地使用String.replace() : 
 String helloWorld = "Hello World!"; String hellWrld = helloWorld.replace("o",""); 
你可以使用StringBuffer
 StringBuffer text = new StringBuffer("Hello World"); text.replace( StartIndex ,EndIndex ,String); 
 replace('regex', 'replacement'); replaceAll('regex', 'replacement'); 
在你的例子中,
 String hi = "Hello World!" String no_o = hi.replaceAll("o", ""); 
看看Apache的StringUtils :
static String replace(String text, String searchString, String replacement)replace另一个string中的string的所有出现。
static String replace(String text, String searchString, String replacement, int max)用一个较大的string内的另一个stringreplacestring的第一个最大值的string。
static String replaceChars(String str, char searchChar, char replaceChar)用另一个replaceString中所有字符的出现。
static String replaceChars(String str, String searchChars, String replaceChars)replacestring中的多个字符。
static String replaceEach(String text, String[] searchList, String[] replacementList)replace另一个string中所有出现的string。
static String replaceEachRepeatedly(String text, String[] searchList, String[] replacementList)replace另一个string中所有出现的string。
static String replaceOnce(String text, String searchString, String replacement)用一个更大的string中的另一个stringreplace一个string。
static String replacePattern(String source, String regex, String replacement)使用Pattern.DOTALL选项replace与指定正则expression式匹配的源string的每个子string。
 你应该看看StringBuilder/StringBuffer ,它允许你在指定的偏移量处删除,插入和replacechar。 
你也可以使用番石榴的 CharMatcher.removeFrom函数。
例:
  String s = CharMatcher.is('a').removeFrom("bazaar"); 
这对我有好处。
 String hi = "Hello World!" String no_o = hi.replaceAll("o", ""); 
或者你可以使用
 String no_o = hi.replace("o", ""); 
  private static void replaceChar() { String str = "hello world"; final String[] res = Arrays.stream(str.split("")) .filter(s -> !s.equalsIgnoreCase("o")) .toArray(String[]::new); System.out.println(String.join("", res)); } 
如果你有一些复杂的逻辑来过滤字符,只是另一种方式,而不是取代。