ArrayList


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: ArrayList

  1. #1
    Join Date
    Dec 2005
    Posts
    27

    ArrayList

    Does anyone know of an easy way to convert Arrays to ArrayLists?

  2. #2
    Join Date
    Dec 2004
    Location
    San Bernardino County, California
    Posts
    1,468
    One element to one node at a time.

  3. #3
    Join Date
    Feb 2006
    Location
    Cologne - Germany
    Posts
    271
    Code:
    // initialize array
    String stringArray [] = new String[10];
    for (int i=0; i<stringArray.length; i++)
      stringArray[i] = Integer.toString(i);
    
    // copy to arraylist
    ArrayList list = new ArrayList();
    for (int i=0; i<stringArray.length; i++)
      list.add(stringArray[i]);
    That's the only possibility i know, since ArrayList has no constructor or
    set method for arrays.
    But there is the method Arrays.asList(Object[]) which will return at least a list (not specifiying which kind of list it uses). The javadocs don't specify if the given array is stored internally in the list or just copied like i did it above.

Similar Threads

  1. ArrayList
    By docfish in forum Java
    Replies: 1
    Last Post: 03-06-2006, 03:36 PM
  2. Replies: 10
    Last Post: 05-15-2005, 06:14 AM
  3. Replies: 4
    Last Post: 04-13-2005, 09:37 PM
  4. Converting arraylist to array
    By warriorwarren in forum Java
    Replies: 11
    Last Post: 03-19-2005, 01:13 PM
  5. Replies: 0
    Last Post: 03-27-2003, 03:09 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center