-1

Syntax for String.join((CharSequence delimiter, Iterable elements))

Well the delimeter I want to use is ',' . Automatically it is getting read as simple comma (,). Can anybody help me with the situation?

Statement I have written is as follows:

String helper = "a,b"; String temp = "','";

helper.replaceAll(",",temp);

After the replace statement, the value of helper is still "a,b". Expected value of helper in "a','b"

NOTE: Even masking in not helping eg

helper.replaceAll("\',\'",temp);

Ousmane D.
  • 54,915
  • 8
  • 91
  • 126
abj1305
  • 635
  • 9
  • 21

1 Answers1

1

It works, but the String is immutable. The method replaceAll(..) returns the new String itself with replacement and you need to assign it to a variable.

String helper = "a,b"; 
String temp = "','";
helper = helper.replaceAll(",",temp);
Nikolas Charalambidis
  • 40,893
  • 16
  • 117
  • 183