所以我有一个 ArrayList“NamedShape”
ArrayList<NamedShape> shapes = new ArrayList<NamedShape>();
包含一个形状和一个字符串,我想要的是另一个 ArrayList“连接”,它将容纳两个字段,但都是“NamedShape”。我的 ArrayList“连接”将如下所示:
这是我的“NamedShape”类(class):
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;
}
}
这是我的连接类:
public class Connection {
private NamedShape namedShape1;
private NamedShape namedShape2;
public Connection(??){
??
}
}
你能帮我创建这个新的ArrayList“连接”吗?
最佳答案
您可以创建另一个包含两个 NamedShape 对象的类。
public class Connection {
private NamedShape namedShapeOne;
private NamedShape namedShapeTwo;
.............
.............
.............
}
现在根据需要创建数组列表
List<Connection> connectionList = new ArrayList<Connection>();
关于java - 如何使用另一个ArrayList的对象创建一个ArrayList?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28874881/