拆分链接列表节点多个数据并显示结果



我想使用文本文件使用Java SE应用程序填充链接列表。文本文件具有以下格式:

FirstNamelastName移动家庭办公室

我想在链接列表中插入这些线作为节点!然后,我想从已从文本文件填充的链接列表中搜索一个特定的节点!

使用firstNamelastName作为键,我想将其与节点数据进行比较(数据是在找到特定的节点后,我想使用split(")找到该节点数据之后,以将其与"键"进行比较)。;并显示结果!!!

我只想知道做这件事的提示,我将非常感谢请帮助我!

我已经生成了Java源代码,但它不起作用,因为它总是会给我最后的节点数据,因此请检查我的错误,如果它完全错误地给出了您的任何想法!

    try {
        String fullname;
        String mobile;
        String home;
        String mobile2;
        String office;
        Node current = first;
        while (current.data != key) {
            String splitter[] = current.data.split(" ");
            fullname = splitter[0];
            mobile = splitter[1];
            home = splitter[2];
            mobile2 = splitter[3];
            office = splitter[4];
            if (fullname == null ? key == null : fullname.equals(key)) {
                mobilefield.setText(mobile);
                homefield.setText(home);
                mobilefield2.setText(mobile2);
                officefield.setText(office);
            } else {
                throw new FileNotFoundException(
                        "SORRY RECORD NOT LISTED IN DATABASE");
            }
            break;
        }
    } catch (Exception e) {
        JOptionPane.showMessageDialog(this, e.getMessage()
                + "nPLEASE TRY AGAIN !", "Search Error",
                JOptionPane.ERROR_MESSAGE);
    }

(key is as=firstname+lastname;)

我将使用arraylist(需要更少的内存,在大多数操作中具有更好的性能)

代码对我来说还可以,但是我不会为每个条目分开current.data

我会使用

之类的测试
if(current.data.startsWith(key)){
  String splitter[]=current.data.split(" ");
  ...
}

,只有在这是真的的情况下,我才会拆分 current.data

最新更新