Create Decade Tuple from another collection in Java

Java 8Object Oriented ProgrammingProgramming

To create Decade Tuple from another collection in Java, use the fromArray() or the fromCollection() method. Here, we will see how to create a Decade Tuple using the fromCollection() method. This method will allow us to crate a Decade Tuple from a List collection in Java.

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

import org.javatuples.Decade;

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 create Decade Tuple from List collection in Java

Example

import java.util.List;
import org.javatuples.Decade;
import java.util.*;
public class Demo {
   public static void main(String[] args) {
      // 10 elements in the List
      List<String> myList = new ArrayList<String> ();
      myList.add("Football");
      myList.add("Cricket");
      myList.add("Tennis");
      myList.add("Hockey");
      myList.add("Badminton");
      myList.add("Archery");
      myList.add("Billiards");
      myList.add("Cycling");
      myList.add("Handball");
      myList.add("Squash");
      // creating Decade Tuple from List
      Decade<String, String, String, String, String, String, String, String, String, String> d = Decade.fromCollection(myList);
      System.out.println("Elements in the Decade Tuple = ");
      for (Object ele : d)
         System.out.println(ele);
   }
}

Output

Elements in the Decade Tuple =
Football
Cricket
Tennis
Hockey
Badminton
Archery
Billiards
Cycling
Handball
Squash
raja
Published on 28-Mar-2019 08:23:28
Advertisements