DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
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

Bookmarks

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


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links