Patrick Patrick - 5 months ago 33
Java Question

Java: how to store data triple in a list?

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

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

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; }

And to instantiate the list:

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