1
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
  • 159
  • 7

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,918
  • 4
  • 21
  • 43
2

Try this to replace all occurrences of . with empty:

mine.replaceAll("\\.", "")
Chaitanya
  • 15,403
  • 35
  • 96
  • 137
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
  • 14,085
  • 9
  • 49
  • 68
Johnkegd
  • 1
  • 1