-2

I have the following String 'user/hello' ,'example/first' , 'stackoverflow/login' etc

I want to modify it as follows user/1/hello, example/1/first , stackoverflow/1/login.

I want to replace first '/' with '/1/'

I tried replaceFirst but I am not able to get the expected result.

String temp = "user/hello";
temp.replaceFirst("/","/1/");
Tunaki
  • 132,869
  • 46
  • 340
  • 423
Salman Shaikh
  • 575
  • 1
  • 7
  • 24

1 Answers1

0

You need to assign the result of replaceFirst back to temp

String temp = "user/hello";
temp = temp.replaceFirst("/","/1/");
Sanjeev
  • 9,876
  • 2
  • 22
  • 33