This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Customer Requirements for Developers and have Marcho Behler on-line!
See this thread for details.
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

Win a copy of Customer Requirements for Developers this week in the Jobs Discussion forum!
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
It's not a secret anymore!