-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
  • 125,519
  • 44
  • 317
  • 399
Salman Shaikh
  • 511
  • 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,798
  • 2
  • 20
  • 33