Compilation error while creating a new ArrayList

I have the following code:

import java.util.*;
import java.io.*;
import java.util.*;
import java.io.*;

public class ShufflingListAndArray
{
   public static void main(String[] args) throws IOException
   {
   List <String> services = new ArrayList<String> (
   Arrays.asList("COMPUTER", "DATA", "PRINTER"));//here I have used List <String> services=new ArrayList<String>( Arrays.asList("COMPUTER", "DATA", "PRINTER"));// followed by next statement Satring s=Services.get(rnd.nextInt(Services.size()));

   String s = services.get(rnd.nextInt(services.size()));

   Collections.shuffle(list);
   //Collections.sort(list);
   System.out.println("List sorting :"+ list);
   }
} 

And when I compile this program, I get the following error:

C:\>javac ShufflingListAndArray.java
ShufflingListAndArray.java:6: '(' or '[' expected
    List<String> services = new ArrayList<String>(
                                         ^
1 error

Can someone help me solve this error?

+5
source share
3 answers

Replace these first lines of the line of your main function as follows:

List<String> services = Arrays.asList("COMPUTER", "DATA", "PRINTER");

Following the example in the documentation of Arrays.asList .

(You also have a double import java.util.*;)

change

, , , , Java 5 ( ), , Generics. 1.4.2 , <String>, .

+2

-source 1.5 -source 1.6, . IDE. Eclipse, NetBeans IntelliJ .

+1

, All ArrayLists

0

All Articles