I need to generate a sequence as follows:
PAY000000 - The first three characters(PAY) remain the same and the 000000 should be incremented by one:
I have tried the following method to generate a sequence number:
public String generateSequence(String currentPayment) {
String chunkNumeric = currentPayment.substring(3, 9);
return "PAY" + (Integer.parseInt(chunkNumeric) + 1);
}
Expected:
currentPayment: PAY000000 Expected value: PAY000001
currentPayment: PAY000001 Expected value: PAY000002
Actual Result:
currentPayment: PAY000001 Actual value: PAY2
The issue is when I pass PAY000001 as parameter the Integer.parseInt(chunkNumeric)
remove all the leading zeros that is PAY2 generated instead of PAY000002.
Any idea how I can increment the string while keeping the leading zero?