File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Adding array to List Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Adding array to List" Watch "Adding array to List" New topic

Adding array to List

Thomas Markl
Ranch Hand

Joined: Mar 08, 2001
Posts: 192
import java.util.*;
public class ListTest {
// Statics
public static void main( String [] args ) {
System.out.println( "List Test" );
// Create a collection
ArrayList list = new ArrayList();

// Adding
String [] toys = { "Shoe", "Ball", "Frisbee" };
list.addAll( Arrays.toList( toys ) );
gives error as follows:
C:\Java\EigeneJavaProgramme>javac cannot resolve symbol
symbol : method toList (java.lang.String[])
location: class java.util.Arrays
list.addAll( java.util.Arrays.toList( toys ) );
1 error

Ilja Preuss

Joined: Jul 11, 2001
Posts: 14112
The method is called asList(...), not toList(...).

The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Dirk Schreckmann

Joined: Dec 10, 2001
Posts: 7023
You'll probably want to learn to become very familiar and comfortable referencing The API Documentation.

[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
I agree. Here's the link:
subject: Adding array to List
jQuery in Action, 3rd edition