aspose file tools*
The moose likes Java in General and the fly likes Arrays.asList() Vs new ArrayList() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Arrays.asList() Vs new ArrayList()" Watch "Arrays.asList() Vs new ArrayList()" New topic
Author

Arrays.asList() Vs new ArrayList()

Sathi Krishna
Ranch Hand

Joined: Oct 21, 2007
Posts: 51

What is the difference between following two code snippets:

1. List<T> list = new ArrayList<T>(Arrays.asList(arrayObj));
2. List<T> list = Arrays.asList(arrayObj);
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 3934
    
  17

The key is in what Arrays.asList() creates. See the API: Which is here. From the method description you should recognize the major difference between the two.


Steve
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3162
    
  10
1 gives you a reference to an ArrayList instance
2 gives you a reference to an instance of a class that implements the List interface.

Joanne
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Arrays.asList() Vs new ArrayList()
 
Similar Threads
error in output
Updating page when uploading files
Getting Session on web service client
groovy's html builder....
JSF 2.0 MyConverter.getAsObject(...) how to get a handle on the backing bean