Java:如何在列表中存储数据三元组? [英] Java: how to store data triple in a list?

查看:2482
本文介绍了Java:如何在列表中存储数据三元组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

java在列表中存储数据三倍的最佳方法是什么?

What's the best way in java to store data triple in a list ?

[a, b, c]
[a, b, c]
... 

我通常使用HashMap数据键+值的数据..我应该去HashMap + Arraylist吗?或者ArrayList + ArrayList?

I usually use HashMap for couples of data key + value.. should I go for HashMap + Arraylist ? or ArrayList + ArrayList ?

谢谢

推荐答案

public class Triplet<T, U, V> {

    private final T first;
    private final U second;
    private final V third;

    public Triplet(T first, U second, V third) {
        this.first = first;
        this.second = second;
        this.third = third;
    }

    public T getFirst() { return first; }
    public U getSecond() { return second; }
    public V getThird() { return third; }
}

并实例化列表:

List<Triplet<String, Integer, Integer>> = new ArrayList<>();

这篇关于Java:如何在列表中存储数据三元组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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