-3

Hi i am using below code to replace the single quote with the ' but it's not working could you please help me out on this?

String name = "Hello's";

name.replaceAll("/'/g", "'");

System.out.println(name);
Behrang
  • 46,888
  • 25
  • 118
  • 160
chandrasekhar
  • 31
  • 1
  • 8

2 Answers2

2

You have to assign your variable with your new value.

String name = "Hello's";

name = name.replaceAll("'", "'");
System.out.println(name);

Hope it helps.

Winter
  • 3,894
  • 7
  • 24
  • 56
1

In Java, strings are immutable. replaceAll returns a new string and you should use that, not the original string.

Behrang
  • 46,888
  • 25
  • 118
  • 160