java有没有类似c_Java是否具有类似于C标准库列表比较器的功...

在Java中,是否有类似于C标准库列表的内容,该列表使用比较器通过其变量之一在列表中查找特定对象?

例如,而不是通过检查变量比较而不是遍历ArrayList来查找特定对象.有没有一种方法可以使用比较器对象查找特定实例?

(注意:我不想使用哈希图,因为那样会创建两个单独的列表.我想要列表的功能而不必涉及哈希图.)

像这样,但对于Java:

#include

using namespace std;

class Cperson

{

string lastname, firstname, address, city;

int zipcode;

char state[3];

// this works for the last name

friend bool operator==(const Cperson& left, const Cperson& right);

friend bool firstEqualTo(const Cperson& left, const Cperson& right);

};

bool operator==(const Cperson& left, const Cperson& right)

{

return left.lastname == right.lastname;

}

bool firstEqualTo(const Cperson& left, const Cperson& right)

{

return left.firstname == right.firstname;

}

现在我们可以在名字字段上搜索我们的人员列表,而忽略其他字段:

vector personlist;

// fill personlist somehow

Cperson searchFor; // should contain the firstname we want to find

vector::iterator fperson;

fperson= std::find(personlist.begin(),

personlist.end(),

searchFor,

firstEqualTo);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值