JavaVector:每个元素包含三个对象。如何根据其中一个的价值进行操作?
例如,我有JavaVector:每个元素包含三个对象。如何根据其中一个的价值进行操作?,java,vector,element,Java,Vector,Element,例如,我有向量(object1,object2,price)。如何打印价格>100的元素 所有的教程和文档(关于以这种方式操作)我只见过处理向量,其中每个元素只包含一个对象 那么,如何在元素中获得一个特定对象的句柄呢?或者这可能吗 一个附带的问题:它们叫什么?也就是说,如果单个元素由多个项组成,那么这些项称为什么?与数据库中一样,记录由字段组成。很难用谷歌搜索你不知道名字的东西 主要内容: InInfo容器类: public class InsInfoContainer { privat
向量(object1,object2,price)
。如何打印价格>100的元素
所有的教程和文档(关于以这种方式操作)我只见过处理向量,其中每个元素只包含一个对象
那么,如何在元素中获得一个特定对象的句柄呢?或者这可能吗
一个附带的问题:它们叫什么?也就是说,如果单个元素由多个项组成,那么这些项称为什么?与数据库中一样,记录由字段组成。很难用谷歌搜索你不知道名字的东西
主要内容:
InInfo容器类:
public class InsInfoContainer {
private Vector<InsuranceInfo> container;
public InsInfoContainer() {
container = new Vector<>(3, 1);
}
public void addInsuranceInfo(InsuranceInfo insu) {
container.addElement(insu);
}
public void print() {
Iterator<InsuranceInfo> iter = container.iterator();
while (iter.hasNext()) {System.out.println(iter.next());}
}
物业类别:
public class Property {
private String type;
private String location;
public Property(final String type, final String location) {
this.type = type;
this.location = location;
}
public String getType() {return this.type;}
public void setType(final String type) {this.type = type;}
public String getLocation() {return this.location;}
public void setLocation(final String sijainti) {this.location = location;}
}
您有一个容器来存储您的
保险信息
:
专用向量容器代码>
您的容器
称为集合
您的InsuranceInfo
容器中的实例被称为元素
保险信息
(属性
,值
)中的“项目”称为属性
或元素的字段
要迭代您的容器
集合,通常的方法是使用for
循环或foreach
循环:
public void print() {
for (InsuranceInfo element: container) {
if (element.getValue() > 100) { // Here is your condition to filter elements
// Process your elements here
}
}
}
您也可以使用迭代器
,流
。您有一个容器来存储您的保险信息
:
专用向量容器代码>
您的容器
称为集合
您的InsuranceInfo
容器中的实例被称为元素
保险信息
(属性
,值
)中的“项目”称为属性
或元素的字段
要迭代您的容器
集合,通常的方法是使用for
循环或foreach
循环:
public void print() {
for (InsuranceInfo element: container) {
if (element.getValue() > 100) { // Here is your condition to filter elements
// Process your elements here
}
}
}
您也可以使用迭代器
,流
。请添加您遇到问题的特定代码,以便获得更好的答案。有关发布的提示,请参阅。顺便说一句,Vector
已被弃用,请使用List
和ArrayList
等。如果我也能通过一些ArrayList的实现获得解决方案,我会很高兴的。或者谷歌的哪些关键词,或者到哪里可以找到相关信息的链接。请添加您有问题的特定代码,以便您可以得到更好的答案。有关发布的提示,请参阅。顺便说一句,Vector
已被弃用,请使用List
和ArrayList
等。如果我也能通过一些ArrayList的实现获得解决方案,我会很高兴的。或者哪些关键词到谷歌,或者链接到哪里可以找到相关信息。
public void print() {
for (InsuranceInfo element: container) {
if (element.getValue() > 100) { // Here is your condition to filter elements
// Process your elements here
}
}
}