Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Adding array to List

 
Thomas Markl
Ranch Hand
Posts: 192
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The method is called asList(...), not toList(...).
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You'll probably want to learn to become very familiar and comfortable referencing The API Documentation.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic