permaculture playing cards*
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
Author

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 ListTest.java
ListTest.java:15: cannot resolve symbol
symbol : method toList (java.lang.String[])
location: class java.util.Arrays
list.addAll( java.util.Arrays.toList( toys ) );
^
1 error

WHY?
Thomas
Ilja Preuss
author
Sheriff

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
Sheriff

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]
 
GeeCON Prague 2014
 
subject: Adding array to List