Tuples
This page is under construction. Please come back later.
import org.pureprogrammer.Tuple; import org.pureprogrammer.Utils; public class Tuples1 { public static void main(String[] args) { Tuple.T2<String, Integer> pair1 = Tuple.makeTuple("Hello", 5); Tuple.T2<Integer, Double> pair2; Tuple.T2<String, Double> pair3; pair2 = Tuple.makeTuple(3, 3.1415926); pair3 = Tuple.makeTuple("Goodbye", 1.5); System.out.println(pair1.first() + "," + pair1.second()); System.out.println(pair2.first() + "," + pair2.second()); System.out.println(Utils.tupleToString(pair3)); } }
Output
$ javac -Xlint Tuples1.java
$ java -ea Tuples1
Hello,5
3,3.1415926
<"Goodbye", 1.5>
import org.pureprogrammer.Tuple; public class Tuples2 { public static void main(String[] args) { Tuple.T2<String, Integer> pair1 = Tuple.makeTuple("Hello", 5); Tuple.T3<String, Integer, Double> tuple1 = Tuple.makeTuple("Goodbye", 3, 3.1415926); Tuple.T4<Double, Double, Integer, String> tuple2 = Tuple.makeTuple(1.6, 2.5, 5, "C"); System.out.println(pair1.first() + "," + pair1.second()); System.out.println(tuple1.first() + "," + tuple1.second() + "," + tuple1.third()); System.out.println(tuple2.first() + "," + tuple2.second() + "," + tuple2.third() + "," + tuple2.fourth()); } }
Output
$ javac -Xlint Tuples2.java
$ java -ea Tuples2
Hello,5
Goodbye,3,3.1415926
1.6,2.5,5,null
Questions
- {{Who's on first?}}
- {{Who's on second?}}
- {{Who's on third?}}
Projects
More ★'s indicate higher difficulty level.
References
- [[Java Language Specification]], Java SE 17 Edition, Gosling, et. al., 2021.
- [[Java Tutorials]]
- [[Java at TutorialsPoint]]
- Download Java at [[Amazon Corretto]], [[Azul Zulu]], [[Eclipse Temurin]] or [[Oracle JDK]]