我想添加一個空arrayList「patternList」到從treeNode類創建的「treeList」arrayList,但我遇到了麻煩填充treeList arrayList空patternList arrayList顯示在代碼的最後一行。基本上我想爲treeList中的每個項目指定一個空arrayList,稍後我將填充它。謝謝。如何將一個空arrayList添加到從類創建的另一個arrayList
import java.util.*;
import java.util.ArrayList;
import java.util.List;
public class testJava{
public static class treeNode {
String nodeName;
String pNodeName;
String fNodeName;
boolean begNode;
boolean targetNode;
int nodeNumber;
//String pattern;
ArrayList<String> patternList = new ArrayList<String>();
public treeNode (String nodeName, String pNodeName, boolean begNode, boolean targetNode, int nodeNumber, ArrayList<String> patternList)
{
this.nodeName = nodeName;
this.pNodeName = pNodeName;
this.begNode = begNode;
this.targetNode = targetNode;
this.nodeNumber = nodeNumber;
this.patternList = patternList;
//this.pattern = pattern;
}
}
public static void main (String[] args){
ArrayList<treeNode> treeList = new ArrayList<treeNode>();
ArrayList<String> openList = new ArrayList<String>();
ArrayList<String> closeList = new ArrayList<String>();
ArrayList<String> treePath = new ArrayList<String>();
String currentNode = "";
String targetNode = "";
int smallestNodeCount = 0;
int tempNodeCount = 0;
int openListCount = 0;
String currentPattern = "" ;
treeList.add(new treeNode ("S 1", null, true, false, 1, ArrayList<string> patternList));