Java Factory Methods

Set<String> set = new HashSet<>();
set.add("foo");
set.add("bar");
set.add("baz");
Set<String> set = Set.of("foo", "bar", "baz");
List<String> list = List.of("foo", "bar", "baz");
Map<String, String> map = Map.of("foo", "a", "bar", "b", "c");
int[] arr = { 1, 2, 3, 4, 5 };
List<int[]> list = List.of(arr);

--

--

--

Sometimes A software Engineer, sometimes a support engineer, sometimes a devops engineer, sometimes a cloud engineer :D That’s how the this life goes!

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Navigating Legacy Code

Thinking Distributed

Websites that helped me as a Web Developer

Package Management on Mac with Homebrew

Prototype Pattern 🤖

3 Questions To Ask Before Making Your First App

Hp Pavilion 513n Recovery Disk Iso Download

My First Project At FlatIron School

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Nuwan Zen

Nuwan Zen

Sometimes A software Engineer, sometimes a support engineer, sometimes a devops engineer, sometimes a cloud engineer :D That’s how the this life goes!

More from Medium

How to use Switch Expressions in Java!

Object Serialization and Deserialization in Java

Java Fundamentals — Method overloading

Arrays in Java