I have three classes.The first class is Node that has 2 variables and the second class is Instance with two variables.The third class which is called Decision has two 2-D arraies the fist one is an 2D array with different types of classes. How Can I make 2D array with different objects of classes(Nodes and Instances)? The second 2D array(y) is type Integer which each dimension is a variable of class Node and class Intances. How can I say for example y[0][0]=1
public class Nodes {
private int nodeID;
private String nodeType;
public Nodes(int nodeID, String nodeType) {
this.nodeID = nodeID;
this.nodeType = nodeType;
}
public int getNodeID() {
return nodeID;
}
public void setNodeID(int nodeID) {
this.nodeID = nodeID;
}
public String getNodeType() {
return nodeType;
}
public void setNodeType(String nodeType) {
this.nodeType = nodeType;
}
}
public class Instances {
private int type;
private int traffic;
public Instances(int Type, int traffic) {
this.type = type;
this.traffic = traffic;
}
public int getType() {
return type;
}
public void setType(int type) {
this.type = type;
}
public int getTraffic() {
return traffic;
}
public void setTraffic(int traffic) {
this.traffic = traffic;
}
}
public class Decision {
Nodes node1=new Nodes();
Instances ins1= new Instances();
private Nodes Instances x[][];
private int [][] y=new int [node1.getNodeID()][ins1.gettype()];
//private Nodes[] node;
//private Instances[] ins;
}
simply you can't , the multi dimensional arrays are most to be considered as an array of array .
How Can I make 2D array with different objects of classes(Nodes and Instances)?
I think it will be easy to do something very similar with java List
and Map
,it does have all the classes you need to go with .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.