Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java : how to replace my last char in a string [duplicate]

Tags:

java

I am trying to replace the last char in my String .

String bowlNumber = 1.1;

bowlNumber.replace(bowlNumber.charAt(bowlNumber.length-1), 2);

By this I am able to replace my last character i.e 1 to 2.. but the problem is as my first character is also 1 , it also changes that to 2.

What i want is to change 1.1 to 1.2 , but it makes 1.1 to 2.2

Any idea?

like image 375
junaidp Avatar asked Mar 14 '26 12:03

junaidp


1 Answers

bowlNumber = bowlnNumber.substring(0,bowlNumber.length()-1) + "2";
like image 53
Matei Suica Avatar answered Mar 16 '26 02:03

Matei Suica



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!