I am getting the following error.
import java.util.*;
import java.io.*;
public class ShufflingListAndArray
{
public static void main(String[] args) throws IOException
{
List services =
//Arrays.asList("COMPUTER", "DATA", "PRINTER");
Arrays.asList(new String[] {"COMPUTER", "DATA", "PRINTER"});
Random rnd=new Random();
String s = services.get(rnd.nextInt(services.size()));
Collections.shuffle(services);
//Collections.sort(list);
System.out.println("List sorting :"+ services);
}
}
After compiling the above code I get the following error.
C:\>javac ShufflingListAndArray.java
ShufflingListAndArray.java:17: incompatible types
found : java.lang.Object
required: java.lang.String
String s = services.get(rnd.nextInt(services.size()));
^
1 error
Change List services ... to List<String> services
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With