I want to change the variable name with each iteration. Since the number of nodes created is dynamically changing.
I tried using one dimensional array but its returning a null pointer. My code is as follow
GenericTreeNode<String> **root1[]** = null;
for(int i=0;i<10;i++)
{
String str="child"+i;
System.out.println(str);
**root1[i]** =new GenericTreeNode<String>(str);
}
I am using already built datastructure
public class GenericTree<T> {
private GenericTreeNode<T> root;
public GenericTree() {
super();
}
public GenericTreeNode<T> getRoot() {
return this.root;
}
public void setRoot(GenericTreeNode<T> root) {
this.root = root;
}
Is there some other way in java or JSP to change the variable name dynamically inside the loop.
root1[] = null;does? Anyway, besides being impossible, "change the variable name with each iteration" makes no sense. You should tell us what you're trying to do.