Results 1 to 1 of 1
Thread: How to convert List to Array
-
How to convert List to Array
Java Code:import java.util.ArrayList; import java.util.List; /** List to array */ public class ToArray { public static void main(String[] args) { List list = new ArrayList(); list.add("Blobbo"); list.add("Cracked"); list.add("Dumbo"); // list.add(new Date()); // Don't mix and match! // Convert a collection to Object[], which can store objects // of any type. Object[] ol = list.toArray(); System.out.println("Array of Object has length " + ol.length); // This would throw an ArrayStoreException if the line // "list.add(new Date())" above were uncommented. String[] sl = (String[]) list.toArray(new String[0]); System.out.println("Array of String has length " + sl.length); } }"The sole cause of man’s unhappiness is that he does not know how to stay quietly in his room." - Blaise Pascal
Similar Threads
-
Convert a vector to a string array
By orchid in forum New To JavaReplies: 4Last Post: 02-24-2010, 02:31 AM -
Converting array to list and sorting it
By Java Tip in forum java.langReplies: 0Last Post: 04-16-2008, 10:36 PM -
Array List Problem
By khamuruddeen in forum New To JavaReplies: 1Last Post: 12-22-2007, 08:10 AM -
using an Array list
By toad in forum New To JavaReplies: 1Last Post: 11-18-2007, 09:08 PM -
how to remove an object from the array list
By cecily in forum New To JavaReplies: 3Last Post: 08-02-2007, 02:26 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks