Use case : How to convert java.util.List to Array & Array to java.util.List in Java
Implementation :
List to Array conversion
List<String> nameList = new ArrayList<String>();
nameList.add("Steve");
nameList.add("Tom");
// Convert List to Array with Generics.
String[] nameArray = nameList.toArray(new String[nameList.size()]);
Array to List conversion
// Convert Arrays to List with Generics
List<String> lastNameList = new ArrayList<String>(Arrays.asList(nameArr));
Implementation :
List to Array conversion
List<String> nameList = new ArrayList<String>();
nameList.add("Steve");
nameList.add("Tom");
// Convert List to Array with Generics.
String[] nameArray = nameList.toArray(new String[nameList.size()]);
Array to List conversion
// Convert Arrays to List with Generics
List<String> lastNameList = new ArrayList<String>(Arrays.asList(nameArr));
No comments:
Post a Comment