Create Decade Tuple from a List collection in Java

Java 8Object Oriented ProgrammingProgramming

Use the fromCollection() method to create 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.

Steps: How to run JavaTuples program in Eclipse

The following is an example to create Decade Tuple from a 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 27-Mar-2019 11:01:43
Advertisements