0
String mine = sc.next();
        String corrected = mine.replace('.', '????');
        System.out.println(corrected);

that's my code. let's assume that my input on String corrected is "<..><.<..>>" , and I want to replace every "." with a null space, so I get an output like "<><<>>". is there any way to do it?

Alex
  • 69
  • 6

3 Answers3

4

If you want to replace . with an empty ("") string, you can just do:

mine.replace(".", "");

Alternatively, you can also check .replaceAll()

Harshal Parekh
  • 5,381
  • 4
  • 16
  • 39
1

Try this to replace all occurrences of . with empty:

mine.replaceAll("\\.", "")
Chaitanya
  • 14,855
  • 32
  • 94
  • 134
0

If you don't want any method, you can do it like this.

String str = "<<.>>.<>.<<.";
String [] parts = str.split("\\.");

for(String s:parts){
    System.out.print(s);
}

Because I tried the method replaceAll(".", "") ; But that method does not allow empty or null spaces in a string. I don't know if it's the best way, but that's what I can think of.

keikai
  • 11,706
  • 7
  • 39
  • 59
Johnkegd
  • 1
  • 1