Category: 08. Java Tuples

  • Unit Class

    Introduction The org.javatuples.Unit class represents a Tuple with single element. Class declaration Following is the declaration for org.javatuples.Unit class − Learn Java in-depth with real-world projects through our Java certification course. Enroll and become a certified expert to boost your career. Class constructors Sr.No. Constructor & Description 1 Unit(A value0)This creates a Unit Tuple. Class Methods Sr.No. Method & Description 1 Pair…

  • Checking Elements

    Each tuple provides utility methods to check their elements in similar fashion as collection. Example Let’s see JavaTuples in action. Here we’ll see how to check elements in a tuple. Create a java class file named TupleTester in C:\>JavaTuples. File: TupleTester.java Verify the result Compile the classes using javac compiler as follows − Now run the TupleTester to…

  • Iteration

    Each tuple implements Iterable interface and can be iterated in similar fashion as collection. Example Let’s see JavaTuples in action. Here we’ll see how to iterate tuples. Create a java class file named TupleTester in C:\>JavaTuples. File: TupleTester.java Verify the result Compile the classes using javac compiler as follows − Now run the TupleTester to see the result…

  • Conversion

    Tuple to List/Array A tuple can be converted to List/Array but at cost of type safety and converted list is of type List<Object>/Object[]. Collection/Array to Tuple A collection can be converted to tuple using fromCollection() method and array can be converted to tuple using fromArray() method. If size of array/collection is different than that of…

  • Remove Elements

    A tuple has removeAtX() methods to remove value at particular index. For example Triplet class has following methods. Removing an element returns a new tuple. Example Let’s see JavaTuples in action. Here we’ll see how to remove value in a tuple. Create a java class file named TupleTester in C:\>JavaTuples. File: TupleTester.java Verify the result Compile…

  • Add Elements

    A tuple has add() method at the end of a tuple and it changes the type of tuple as well. For example adding a element to Triplet tuple will convert it to a Quartet tuple. A tuple has addAtX() methods as well to add a position at particular index starting from 0. A tuple can…

  • Set Values

    A tuple has setAtX() methods to set value at particular index. For example Triplet class has following methods. Feature Example Let’s see JavaTuples in action. Here we’ll see how to set values in a tuple using various ways. Create a java class file named TupleTester in C:\>JavaTuples. File: TupleTester.java Verify the result Compile the classes using javac compiler…

  • Get Values

    A tuple has getValueX() methods to get values and getValue() a generic method to get value by index. For example Triplet class has following methods. Feature Example Let’s see JavaTuples in action. Here we’ll see how to get values from a tuple using various ways. Create a java class file named TupleTester in C:\>JavaTuples. File: TupleTester.java…

  • Create Tuples

    A tuple using JavaTuple classes can be created using multiple options. Following are the examples − Using with() Methods Each tuple class has a with() method with corresponding parameters. For example − Using Constructor Each tuple class has a constructor with corresponding parameters. For example − Learn Java in-depth with real-world projects through our Java certification course. Enroll…

  • Environment Setup

    Local Environment Setup If you are still willing to set up your environment for Java programming language, then this section guides you on how to download and set up Java on your machine. Please follow the steps mentioned below to set up the environment. Java SE is freely available from the link Download Java. So you…