How to replace first occurrence of string in Java April 6, 2023 by Tarik You can use replaceFirst(String regex, String replacement) method of String.