所以我有一个ArrayList“ NamedShape”
ArrayList<NamedShape> shapes = new ArrayList<NamedShape>();
包含一个形状和一个字符串,我想要的是拥有另一个ArrayList“ Connection”,它将容纳两个字段,但两者均为“ NamedShape”。我的ArrayList“连接”将如下所示:
这是我的“ NamedShape”类:
public class NamedShape {
private String name;
private Shape shape;
public NamedShape( String name, Shape shape ){
this.name = name;
this.shape = shape;
}
public String getName(){
return name;
}
public Shape getShape(){
return shape;
}
}
这是我的Connection类:
public class Connection {
private NamedShape namedShape1;
private NamedShape namedShape2;
public Connection(??){
??
}
}
您能帮我创建这个新的ArrayList“ Connection”吗?
最佳答案
您可以创建另一个包含两个NamedShape对象的类。
public class Connection {
private NamedShape namedShapeOne;
private NamedShape namedShapeTwo;
.............
.............
.............
}
现在根据需要创建数组列表
List<Connection> connectionList = new ArrayList<Connection>();