You can do this in different ways, you just need some kind of calculation, there are no specific api or build methods. You can also do this below.
String str = "RoomA38"; int number = 0; String[] strArr = str.split("\\d"); str = str.replace(strArr[0], ""); number = Integer.parseInt(str); System.out.println("Numbers::: " + number); str = strArr[0]; System.out.println("String is:::: " + str);
source share