-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
  • 44,452
  • 23
  • 114
  • 153

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,591
  • 7
  • 23
  • 51
1

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

Behrang
  • 44,452
  • 23
  • 114
  • 153