简体   繁体   English

如何在链表节点中创建字符串数组

[英]How to create an array of strings in a linked list node

I've been playing around with linked lists and I want to know if it's possible to have an array of strings in a linked list node.我一直在玩链表,我想知道是否可以在链表节点中有一个字符串数组。 I've been trying to get it to work the same way as the string "name", so that I can insert more strings into the array as needed我一直试图让它以与字符串“name”相同的方式工作,以便我可以根据需要将更多字符串插入到数组中

class Test1 {
    public static void main(String[] args) {
        Node n = new Node("Ace");
    }
}

class Node {
    private Node next;
    private String name;
    private String[] data;

    public Node(String s1) {
        s1 = name;
        next = null;
    }

    public String[] getArray() {
        return array;
    }

    public void setData(String s1, int point) {
        name = s1;
        array
    }

    public Node getNext() {
        return next;
    }

    public void setNext(Node nextVal) {
        next = nextVal;
    }
}

You can have a String array in your linked list, but you cannot extend an array once it is allocated.链表中可以有一个 String 数组,但一旦分配了数组,就不能扩展它。

If you want to have something extensible, you should use an ArrayList .如果你想要一些可扩展的东西,你应该使用ArrayList

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM