- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Implement Pair Class with Unit Class in Java using JavaTuples
Following is an example to implement Pair class from Unit class in Java −
Example
import org.javatuples.Unit; import org.javatuples.Pair; public class MyDemo { public static void main(String[] args) { Unit<String> unit = Unit.with("Tutorial"); System.out.println("Unit class element: " + unit); Pair<String, String> pair = unit.addAt0("Learning"); System.out.println("Pair (Implemented from Unit Tuple): " + pair); } }
Output
Unit class element: [Tutorial] Pair (Implemented from Unit): [Learning, Tutorial]
Let us see another example wherein we will be implementing Pair class from Unit class −
Example
import org.javatuples.Unit; import org.javatuples.Pair; public class MyDemo { public static void main(String[] args) { Unit<String> unit = Unit.with("Tutorial"); System.out.println("Unit class element = " + unit); Pair<String, String> pair = unit.addAt1("Learning"); System.out.println("Pair Class (Implemented from Unit Tuple) = " + pair); } }
Output
Unit class element = [Tutorial] Pair Class (Implemented from Unit Tuple) = [Tutorial, Learning]
Advertisements