So I have, for example, a string such as this C3H20IO
What I wanna do is split this string so I get the following:
Array1 = {C,H,I,O}
Ar
You can use two patterns :
Split twice by each of them.
List letters = Arrays.asList(test.split("[0-9]"));
List numbers = Arrays.asList(test.split("[a-zA-Z]"))
.stream()
.filter(s -> !s.equals(""))
.collect(Collectors.toList());
if(letters.size() != numbers.size()){
numbers.add("1");
}