I'm learning about Lists in java but I'm having a hard time returning it from a method like I would any primitive data type. All I'm trying to do is return a list of nodes and then print out all their labels. What am I doing wrong?
import java.util.ArrayList;
import java.util.List;
public class TestingArrays
{
List<Node> myList1 = new ArrayList<Node>();
List<Node> myList2 = new ArrayList<Node>();
List<Node> myList3 = new ArrayList<Node>();
List<Node> myList4 = new ArrayList<Node>();
private Node Node1 = new Node("One", myList1);
private Node Node2 = new Node("Two", myList2);
private Node Node3 = new Node("Three", myList3);
private Node Node4 = new Node("Four", myList4);
public static void main(String arg[])
{
List<Node> nodeList = nodeArray();
for (int i = 0; i < nodeList.size(); i++)
{
System.out.println(nodeArray.get(i).label);
}
}
public List<Node> nodeArray()
{
List<Node> tempList = new ArrayList<Node>();
tempList.add(Node1);
tempList.add(Node2);
tempList.add(Node3);
tempList.add(Node4);
return tempList;
}
}