Having a string (any string). It may not contain numbers;
How can I store the integers contained in that array into an ArrayList.
Tried to
public ArrayList<Integer> toList() {
String stringToList;
ArrayList<Integer> l = new ArrayList<>();
stringToList = this.toString(); // I am just copying the string from the object
for (int i = 0; i < stringToList.length(); i++) {
if(((Integer) stringToList.charAt(i)) instanceof Integer){
//Here store it into the arrayList
}
}
return l;
}
But obviously it does not work because the cast is not the solution. Any ideas? Thanks.

Since there may exist such as
12in the string, you can not usecharAt()directly. You can split thestringToListwith,and then useInteger.parseInt()