GeeCON Prague 2014*
The moose likes Beginning Java and the fly likes Is it hard to convert from an Array to an Array list? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Is it hard to convert from an Array to an Array list?" Watch "Is it hard to convert from an Array to an Array list?" New topic
Author

Is it hard to convert from an Array to an Array list?

Reem Akira
Greenhorn

Joined: Dec 14, 2012
Posts: 6
I have an array and I need to convert it into an array list? How hard would that be? Is there anything I should be aware of before starting making changes?
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4575
    
    5

Reem Akira wrote:I have an array and I need to convert it into an array list? How hard would that be?

A three-liner, including the initialization of the ArrayList. And if you don't specifically need an ArrayList but a fixed size List will do, that's a one-liner.

Reem Akira wrote:Is there anything I should be aware of before starting making changes?

The JavaDoc for java.util.ArrayList and java.util.Arrays.


luck, db
There are no new questions, but there may be new answers.
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 7898
    
  21

Darryl Burke wrote:And if you don't specifically need an ArrayList but a fixed size List will do, that's a one-liner.

Actually, it's a one-liner either way, because you can initialize an ArrayList from any Collection.

Winston


Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
 
GeeCON Prague 2014
 
subject: Is it hard to convert from an Array to an Array list?