快速Java链接列表问题
基本上,我是Java新手,在理解一行代码并使其正常工作方面遇到了问题 这是代码行:快速Java链接列表问题,java,list,loops,client,Java,List,Loops,Client,基本上,我是Java新手,在理解一行代码并使其正常工作方面遇到了问题 这是代码行: LinkedList<ClientWorkers> clients = SingletonClients.getClients(); LinkedList clients=SingletonClients.getClients(); 程序如下: ClientWorker(Socket client, JTextArea textArea) { this.client = clien
LinkedList<ClientWorkers> clients = SingletonClients.getClients();
LinkedList clients=SingletonClients.getClients();
程序如下:
ClientWorker(Socket client, JTextArea textArea) {
this.client = client;
this.textArea = textArea;
String line = in.readLine();
LinkedList<ClientWorkers> clients = SingletonClients.getClients();
for(int i = 0; i < clients.size(); i++) {
ClientWorker c = clients.get(i);
//The client doesn't need to get it's own data back.
if(c == this){
continue;
}
c.writeString(line);
}
}
ClientWorker(套接字客户端,JTextArea textArea){
this.client=client;
this.textArea=textArea;
String line=in.readLine();
LinkedList clients=SingletonClients.getClients();
对于(int i=0;i
它抛出的错误有:
SocketThrdServer.java:20: cannot find symbol
symbol : class LinkedList
location: class ClientWorker
LinkedList<ClientWorker> clients = SingletonClients.getClients();
^
SocketThrdServer.java:20: cannot find symbol
symbol : variable
SingletonClients location: class ClientWorker
LinkedList<ClientWorker> clients = SingletonClients.getClients();
SocketThrdServer.java:20:找不到符号
符号:类链接列表
位置:类ClientWorker
LinkedList clients=SingletonClients.getClients();
^
SocketThrdServer.java:20:找不到符号
符号:变量
SingletonClient位置:类ClientWorker
LinkedList clients=SingletonClients.getClients();
有人知道我怎么把它分类吗?我假设LinkedList的定义是错误的,而SingletonClient根本没有定义,但我不确定在这种情况下如何定义它们
提前谢谢 排队
LinkedList<ClientWorkers> clients = SingletonClients.getClients();
LinkedList clients=SingletonClients.getClients();
你写的是ClientWorkers而不是ClientWorker。这是一个错误。
应该是:
LinkedList<ClientWorker> clients = SingletonClients.getClients();
LinkedList clients=SingletonClients.getClients();
在行中
LinkedList<ClientWorkers> clients = SingletonClients.getClients();
LinkedList clients=SingletonClients.getClients();
你写的是ClientWorkers而不是ClientWorker。这是一个错误。
应该是:
LinkedList<ClientWorker> clients = SingletonClients.getClients();
LinkedList clients=SingletonClients.getClients();
您需要导入java.util.LinkedList如果您希望使用LinkedList而不使用其完全限定名(即,如果您希望能够说“LinkedList”而不是“java.util.LinkedList”),请在java文件的开头使用code>。您需要导入java.util.LinkedList如果您想使用LinkedList而不使用其完全限定名(即,如果您想说“LinkedList”而不是“java.util.LinkedList”),请在java文件的开头使用code>。听起来像是类路径问题,尽管LinkdList属于java.util包,所以它总是可用的。我建议您检查类文件顶部的import语句,看看是否使用了正确的LinkedList类,尽管LinkdList属于java.util包,因此始终可用,但听起来像是类路径问题。我建议您检查类文件顶部的import语句,看看是否使用了正确的LinkedList类(主题外):按索引在LinkedList
上循环速度非常慢。使用迭代器
(或新的foreach语法)(主题外):按索引在链接列表
上循环的速度非常慢。改用迭代器(或新的foreach语法)。非常感谢!我从没注意到!你知道如何定义SingletonClients吗?它应该是一个名为SingletonClients的类,内部有一个名为getClients()的静态方法,该方法返回一个LinkedList。类似于:公共类SingletonClients{public static LinkedList getClients(){//your code}}非常感谢!我从没注意到!你知道如何定义SingletonClients吗?它应该是一个名为SingletonClients的类,内部有一个名为getClients()的静态方法,该方法返回一个LinkedList。类似于:公共类SingletonClients{public static LinkedList getClients(){//your code}}完美!谢谢你知道如何定义SingletonClient吗?太好了!谢谢你知道如何定义SingletonClient吗?没错!谢谢:戴耶,就是这样!谢谢:D