How to add to string number and keep string in Java?

Assuming you know that the String age is a valid number (if you don’t know it is a valid number you will have to add some code to check for this).

You can simply convert age using Integer.parseInt then add the int 10 and the convert the result back to a String using String.valueOf:

String age = "14";
age = String.valueOf(Integer.parseInt(age) + 10);
System.out.println(age); // 24

Leave a Comment