class Main {
public static void main(String[] args) {
String s = "a-b-c-d";
// replace swaps every literal occurrence
System.out.println(s.replace("-", "_"));
// replaceFirst takes a regex and changes one match
System.out.println(s.replaceFirst("-", "_"));
}
}replace all, or just the first