Implement Triplet class in Java using Pair class

In this post, we will see how to implement our own Triplet class in Java using Pair class provided by many Java third-party libraries.


 

A Triplet is just container to store a sequence of three objects that are unrelated to each other. Since JDK doesn’t provides any implementation of the Triplet class, many programmers often miss this class in Java.

In the previous post, we have seen how to implement our own Triplet class in Java. In this post, we will see how to implement a Triplet class using Pair class from Apache Commons.

 

Download Code

Output:

ASCII, 65, A

 
Above implementation is little verbose. Below is simplified, cleaner version of above program –

 

Download Code

Output:

ASCII, 65, A

 
Thanks for reading.




Please use ideone or C++ Shell or any other online compiler link to post code in comments.
Like us? Please spread the word and help us grow. Happy coding 🙂
 





Leave a Reply

Notify of
avatar
wpDiscuz