O'Reilly logo

Java 9 Cookbook by Nick Samoylov, Mohamed Sanaulla

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How to do it...

  1. Create the required Java code for Java 8 platform. We will add two classes CollectionUtil.java and FactoryDemo.java in the directory src\8\com\packt:
        public class CollectionUtil{          public static List<String> list(String ... args){            System.out.println("Using Arrays.asList");            return Arrays.asList(args);          }          public static Set<String> set(String ... args){            System.out.println("Using Arrays.asList and set.addAll");            Set<String> set = new HashSet<>();            set.addAll(list(args));            return set;          }        }        public class FactoryDemo{          public static void main(String[] args){            System.out.println(CollectionUtil.list("element1",                        "element2", "element3"));            System.out.println(CollectionUtil.set("element1",       

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required