Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Reem Akira
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5148
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Winston Gutkowski
Bartender
Pie
Posts: 10492
64
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic