【发布时间】:2022-01-17 14:11:21
【问题描述】:
下面是我想从包含对象的向量中找到包含 str="test" 的索引对象的示例代码。
class Abc{
String str1;
String str2;
}
class Test{
Vector vector = new Vector();
Abc obj1 = new Abc();
obj1.str1 = "test";
Abc obj2 = new Abc();
obj2.str1 = "test2";
vector.add(obj1);
vector.add(obj2);
//now i want index of that object which have str="test"
//it should give 0 (object 0 contain test)
//with loop we can easily get but do we get that by using //streams or indexOf method
}
【问题讨论】: