I have a string-array resource with integers.
<string-array name="navChildRatings">
<item>12</item>
<item>12</item>
<item>17</item>
<item>123</item>
<item>8</item>
</string-array>
My goal is to have them into a list of type List<Integer>
As a first step I know they can be assigned into an integer array by:
int[] ratings = Arrays.asList(getResources().getIntArray(R.array.navChildRatings));
I am trying to avoid looping through the array of integers (ints) and having to add one by one to the List of Integers (java.lang.Integer).
- Is there a direct way to get the string-array into a
List<Integer>
?
or, alternatively - Is there a direct way to assign the
int[]
array to aList<Integer>
?
Note: My motivation is purely to have a more elegant code. I know how to do it by looping the array. But, for example, in the case of Strings it works if you assign it directly:
List<String> names = Arrays.asList(getResources().getStringArray(R.array.navChildNames));