Java集合。员工商店集合 [英] Java Collections. Collection for an Employee Store

查看:64
本文介绍了Java集合。员工商店集合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,我只是想知道在为员工详细信息(例如姓名,年龄地址,出生日期,工资和电子邮件地址)创建商店时,最适合使用什么收藏夹。

Hey im just wondering what would be the best collection to use when creating a store for employee details such as name, age address, dob, wages and email address. the store needs all the bare essentials such as add, edit, remove, remove all and searchBy.

推荐答案

好吧,商店可能需要所有基本要素,例如添加,编辑,删除,全部删除和searchBy。想要快速搜索,因此将关键字作为您要搜索的对象的哈希结构可能是最好的解决方案。例如,如果您想按名称搜索,则可以创建如下这样的类:

Well you'd probably want a fast search, so a hashing structure with the key as the fiend you want to search by could be the best solution. For example, if you want to search by name, you can create a class like this:

public class EmployeeStore {
    private Map<String, Employee> employees;

    public EmployeeStore() {
        employees = new HashMap<String, Employee>();
    }

    public void add(Employee e) {
        employees.add(e.getName(), e);
    }

    public Employee searchByName(String name) {
        return employees.get(name);
    }

    // etc.
}

并使用员工数据结构根据您的需求实施所需的方法。如果按名称进行搜索,则可以将名称作为关键字字符串。

and implement the required methods based on your needs using the employees data structure. If the search is done by name you can have the name as the key string.

不幸的是,按与索引不同的字段进行搜索将需要进行线性搜索,即如果您有大量条目,速度会很慢。

Unfortunately, searching by a different field than the index will require a linear search which will be slow if you have a huge number of entries.

这篇关于Java集合。员工商店集合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆