I have a string that I want to split with a certain delimiter
private int [] mMaxValues;
public void setMaximum(String maximum) {
mMaxValues = splitByDelimiter(maximum, ":");
}
But the splitByDelimiter method return a string array into an int array
public String[] splitByDelimiter(String list,String delimiter) {
String[] items = list.split("\\" + delimiter);
for (String s : items) {
s.trim();
}
return items;
}
What is the best way to fix this problem? I'm guessing that iterating the string array and casting them to integers isn't the best solution.
I could also create a new splitByDelimiter that returns an int array but I'm guessing there is a better solution than that..
Is this a situation where you could use generics (I don't have a lot of experience with generics)?
Thx :)
int, you need to parse it and there is no way to do this automagically.String[]only contains Strings that can be parsed to an Integer? In other words it contains numbers as Strings?!forloop isn't doing anything. Strings are immutable, so you're trimming the copy of the strings in array.String[]that cannot be parsed to an Integer? Do you simply want to ignore them? It's always useful to provide some sample input and the expected output. Input:"bla:123:456:blub:789", Output:{123,456,789}or something like that ...