Tagged: #list

Java – Convert comma-separated String to List

This tutorial shows several ways for converting a comma-separated String to a List in Java. 1- Java 7 With Java 7 and older versions, the typical way of converting a comma-separated String to a List is through splitting the String by the comma “,” delimiter and then generating a List using Arrays.asList() as the following:

2- Java 8 In...

Java – Convert List to Array

This tutorial shows several ways to convert a List to Array in Java. 1- toArray() List provides a utility method called toArray() which accepts an empty array and populates it with the elements of the array list.

In the above example, we initialize an array with the same number of elements as the input list, then we populate it...

Java – Convert Array to List

This tutorial shows several ways to convert Array to List in Java. 1- Arrays.asList You can convert an Array to List using Arrays.asList() utility method. This method accepts an array as input and returns a list as output.

The limitation of using this method is that it returns a fixed size list. You can just read and overwrite its...

Java – Convert List to Map

This tutorial shows the different ways to convert a List to Map in Java. 1- Java 7 & before With Java 7 and older releases, the only way to convert a List to Map is to iterate over the list and populate the map manually. In the following example, we implement a utility method which accepts a list of Student...