Patrick Patrick -4 years ago 100
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 ?


Answer Source
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<>();
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download