How to work with pairs in java without using maps?

is it possible to work with pairs in online ide’s in java without using maps because maps doesn’t works in every matter when dealing with pairs . Is there something like the pair in java just like in c++?

In java collections there is no such class or interface like pairs of c++ stl. But we can create a custom class of pairs and then use it with any generic collection.

Create custom class:

class Pair{

int first;
int second;
}

1 Like

There’s no built-in Pair class in JAVA.
You can create custom class.

`
class Pair<E,V> {

    E first;
    V second;
    Pair(E e, V v) {
        this.first = e;
        this.second = v;
    }

}
`
This generic class can be used for any kind of data types as well as for your custom defined classes.