Use random numbers to list in Java
•
Java
I received 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","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
Solution
Change list service to list < string > Service
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码