What is the addAtX() method of the Ennead Tuple in Java

Java 8Object Oriented ProgrammingProgramming

To add value in Ennead class in JavaTuples, you need to use the addAtX() method. Here, X represents the index wherein you need to add the value i.e. for index 2, use addAt2() method. Add the specific value as the parameter value of the method. For example −

addAt2(“John”);

Let us first see what we need to work with JavaTuples. To work with Ennead class in JavaTuples, you need to import the following package −

import org.javatuples.Ennead;

Note − Download JavaTuples Jar library to run JavaTuples program. If you are using Eclipse IDE, then Right Click Project -> Properties -> Java Build Path -> Add External Jars and upload the downloaded JavaTuples jar file. Refer the below guide for all the steps to run JavaTuples −

StepsHow to run JavaTuples program in Eclipse

The following is an example to add value in Ennead Tuple in Java −

Example

import org.javatuples.Ennead;
public class Demo {
   public static void main(String[] args) {
      Ennead<String, String, String, String, String, String, String, String, String> e =
         Ennead.with("Katie", "Tom","Ryan", "Tom","Bradley", "David","Steve", "Brad", "Jacob");
      System.out.println("Elements in the Tuple = "+e.addAt0("Newton"));
      System.out.println("Elements in the Tuple = "+e.addAt2("Stephen"));
      System.out.println("Elements in the Tuple = "+e.addAt5("Sam"));
      System.out.println("Elements in the Tuple = "+e.addAt7("Mark"));
   }
}

Output

Elements in the Tuple = [Newton, Katie, Tom, Ryan, Tom, Bradley, David, Steve, Brad, Jacob]
Elements in the Tuple = [Katie, Tom, Stephen, Ryan, Tom, Bradley, David, Steve, Brad, Jacob]
Elements in the Tuple = [Katie, Tom, Ryan, Tom, Bradley, Sam, David, Steve, Brad, Jacob]
Elements in the Tuple = [Katie, Tom, Ryan, Tom, Bradley, David, Steve, Mark, Brad, Jacob]
raja
Published on 27-Mar-2019 11:03:08
Advertisements