i want to increase string ID like "S1001" to "S1002" in netbeans

32 Views Asked by At

check image for information

im using netbeans javaDB. when i press the new id button, i want to increase to "S1004" and show in text field i want get last id from database how can i do that?

1

There are 1 best solutions below

0
JoeChris On

i want to increase string ID like “S1001” to “S1002”

This will work for your example

String id = "S1001";

String num = id.substring(1); // remove first char
int num = Integer.parseInt(num) + 1; // convert to int and increment

id = ("S" + num); // convert it back