how to separate no and text in java
String input = "C3H20IO";
List<String> array1 = new ArrayList<String>();
List<Integer> array2 = new ArrayList<Integer>();
Pattern pattern = Pattern.compile("([A-Z][a-z]*)([0-9]*)");
Matcher matcher = pattern.matcher(input);
while(matcher.find()){
array1.add(matcher.group(1));
String atomAmount = matcher.group(2);
int atomAmountInt = 1;
if((atomAmount != null) && (!atomAmount.isEmpty())){
atomAmountInt = Integer.valueOf(atomAmount);
}
array2.add(atomAmountInt);
}
Also in Java:
- java cannot find file path
- java output array lists to file
- java strin to int
- how to check if rs next is null
- hashset contains java
- java print type of object
- java initialize string array
- java stack methods
- equls en java
- funzione random in java
- java identifiers
- money value commas java
- cannot lock java compile cache as it has already been locked by this process
- multiplication program java
- for each loop java
- if en une seul ligne java
- java.sql.SQLException: Before start of result set
- how timer class and display to jtextfield w3schools in java
- java map get the key from value
- java int stream min
- java console text color
- Spigot API inventory close
- array string java in one line
- foreach java