Let's also add asList() doing Arrays.asList(IntListUtil.unbox()) is annoying.
This is not as efficient as it could be (it doesn't create a List backed by the int[], instead it creates an ArrayList). git-svn-id: https://samskivert.googlecode.com/svn/trunk@2542 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
@@ -20,8 +20,10 @@
|
||||
|
||||
package com.samskivert.util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This class manages arrays of ints. Some of those routines mimic the
|
||||
@@ -504,6 +506,21 @@ public class IntListUtil
|
||||
return boxed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts an array of primitives to a list of Integers.
|
||||
*/
|
||||
public static List<Integer> asList (int[] list)
|
||||
{
|
||||
if (list == null) {
|
||||
return null;
|
||||
}
|
||||
List<Integer> ilist = new ArrayList<Integer>(list.length);
|
||||
for (int ii = 0; ii < list.length; ii++) {
|
||||
ilist.add(list[ii]);
|
||||
}
|
||||
return ilist;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts an array of Integer objects to an array of primitives.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user