or if there is quick way to convert array to arraylist without using the for loop.
I thought Arrays might have something, but it only has binary search on sorted arrays. But is also has a sort method so you could sort your array! You might time the actual overhead of creating a list from your array so you can use the nicer List APIs. I'd probably do that until somebody proves it's too slow, whicih I wouldn't expect unless you have zillions of items or call this a million times a second. Of course you could maybe change your design to use Lists in the first place
[ May 09, 2005: Message edited by: Stan James ]
I am not sure there is a way to convert an array into an ArrayList, but insted of using a lot of for loops all over your code, you can simply create your own "contains" method and use it instead of cloning the for loops. Or you can convert your arrays into arrayList.
You can do something like:
Is this helpful?
[ May 09, 2005: Message edited by: Giovanni De Stefano ]
Arrays does have a method. Check out Arrays.asList(Object a)
From the javadoc:
public static List asList(Object�a)
Returns a fixed-size list backed by the specified array. (Changes to the returned list "write through" to the array.) This method acts as bridge between array-based and collection-based APIs, in combination with Collection.toArray.
The returned list is serializable and implements RandomAccess.
a - the array by which the list will be backed.
a list view of the specified array.
By the way, I totally agree with Stan James. When you type something for the third time, it's time to refactor!
[ May 09, 2005: Message edited by: Timmy Marks ]
Of course, the implementation is pretty much the same thing that you might do in your code with a for loop or the same as a util library you might create, it's just already done and contained within Commons Lang. I've found a number of their helper utilities to be very convenient.
Hope that's helpful.