【问题标题】:add linked list java添加链表java
【发布时间】:2017-05-09 15:11:17
【问题描述】:

我需要在链表中添加一个“用户”,而链表是链表的一部分。

public void shibutz(user a){

    this.serverList(this.placeInServerList(a.code)).add(a);

服务器列表是链表的链表。 这些是该行使用的类:

public int placeInServerList(String code){
    if (this.serverList.contains(code)){
        return indentifyCode(code);
    }
    return -42;
}
public int indentifyCode (String code){
    int counter=0;
    Group i= this.serverList.getFirst();
    while (this.serverList!=null){
        if (i.getCode()==code){
            return counter; }
        counter++;
        i=this.serverList.get(counter);
        return indentifyCode (code);
    }
    return -42;}

group 是一个链表。 现在,我需要第一个代码部分的帮助。我不明白 Eclipse 想从我这里得到什么。它给我的解决方案都不是相对的。谢谢!!!

【问题讨论】:

  • 有什么问题...?代码的作用与您希望它做什么?
  • 您需要使用equals 才能正确比较字符串。这行代码`if (i.getCode()==code){`应该替换为i.getCode().equals(code),因为codeStringpublic int indentifyCode (String code)

标签: java eclipse linked-list add


【解决方案1】:

阅读这一行:

Group i = this.serverList.getFirst()

我假设serverListLinkedList<Group>

因此,这是无效的:

public int placeInServerList(String code){
  //code is a String, not a Group
  if (this.serverList.contains(code))

由于serverListLinkedList<Group>,你可以调用的方法是serverList.contains(Group)。方法serverList.contains(String)不存在。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-26
    • 2019-07-16
    • 2020-03-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多