In my code I am converting an ArrayList<String> to int[] by using this code.
ArrayList<String> oneList = new ArrayList<String>();
oneList.add("7");
oneList.add("525");
oneList.add("85");
oneList.add("365");
oneList.add("78");
oneList.add("1");
String[] stringArray = oneList.toArray(new String[oneList.size()]);
int[] arrayOfValues = new int[oneList.size()];
for(int i = 0;i < stringArray.length;i++)
{
try
{
arrayOfValues[i] = Integer.parseInt(stringArray[i]);
}
catch(Exception e)
{
System.out.println("Not an integer value");
}
}
Is this the most efficient way of completing this or should I be going about it differently? I would also be interested in any alternatives to the way I did it if you have one.