I am having the following java code, in which I am trying to copy the ArrayList to another ArrayList.
ArrayList nodes = new ArrayList
Mainly, you've got 2 major problems:
You are using adding a List of Strings. You want a List containing Lists of Strings.
Note as well that when you invoke this:
NodeList.addAll(nodes);
... all you say is to add all elements of nodes (which is a list of Strings) to the (badly named) NodeList, which is using Objects and thus adds only the strings inside. Which leads me to the next point.
You seem to be confused between your nodes and NodeList. Your NodeList keeps growing over time, and that's what you add to your list.
So, even if doing things right, if we were to look at the end of each iteration at your nodes, nodeList and list, we'd see:
i = 0
nodes: [PropertyStart,a,b,c,PropertyEnd]
nodeList: [PropertyStart,a,b,c,PropertyEnd]
list: [[PropertyStart,a,b,c,PropertyEnd]]
i = 1
nodes: [PropertyStart,d,e,f,PropertyEnd]
nodeList: [PropertyStart,a,b,c,PropertyEnd, PropertyStart,d,e,f,PropertyEnd]
list: [[PropertyStart,a,b,c,PropertyEnd],[PropertyStart,a,b,c,PropertyEnd, PropertyStart,d,e,f,PropertyEnd]]
i = 2
nodes: [PropertyStart,g,h,i,PropertyEnd]
nodeList: [PropertyStart,a,b,c,PropertyEnd,PropertyStart,d,e,f,PropertyEnd,PropertyStart,g,h,i,PropertyEnd]
list: [[PropertyStart,a,b,c,PropertyEnd],[PropertyStart,a,b,c,PropertyEnd, PropertyStart,d,e,f,PropertyEnd],[PropertyStart,a,b,c,PropertyEnd,PropertyStart,d,e,f,PropertyEnd,PropertyStart,g,h,i,PropertyEnd]]
and so on...
Don't use variable names starting with uppercase letters. So here, replace NodeList with nodeList).
You say "I want the "list" array [...]". This is confusing for whoever you will be communicating with: It's not an array. It's an implementation of List backed by an array.
There's a difference between a type, an interface, and an implementation.
Use generic types, because static typing really helps with these errors. Also, use interfaces where possible, except if you have a good reason to use the concrete type.
So your code becomes:
List nodes = new ArrayList();
List nodeList = new ArrayList();
List> list = new ArrayList>();
You could do away with the nodeList entirely, and write the following once you've fixed your types:
list.add(nodes);
Except if you have a very strong reason to do so, prefer to use the inner-most scope to declare variables and limit both their lifespan for their references and facilitate the separation of concerns in your code.
Here you could then move List to be declared within the loop (and then forget the nodes.clear() invocation).
A reason not to do this could be performance, as you might want to avoid recreating an ArrayList on each iteration of the loop, but it's very unlikely that's a concern to you (and clean, readable and maintainable code has priority over pre-optimized code).
Last but not least, if you want help give us the exact reproducible case with a short, self-Contained, correct example.
Here you give us your program's outputs, but don't mention how you got them, so we're left to assume you did a System.out.println(list). And you confused a lot of people, as I think the output you give us is not what you actually got.