1.

How To Convert An Array Of String To Arraylist?

Answer»

This is more of a programmatic question which is seen at beginner level. The intent is to check the KNOWLEDGE of applicant in Collection utility classes. For now, lets LEARN that there are two utility classes in Collection FRAMEWORK which are mostly seen in interviews i.e. Collections and Arrays.

Collections class provides some static functions to perform specific operations on collection types. And Arrays provide utility functions to be performed on array types.

//String array
String[] WORDS = {"ace", "boom", "crew", "dog", "eon"};
//Use Arrays utility class
List wordList = Arrays.asList(words);
//Now you can iterate over the list
Please not that this function is not specific to String class, it will return List of element of any type, of which the array is. e.g.

//String array
Integer[] NUMS = {1,2,3,4};
//Use Arrays utility class
List numsList = Arrays.asList(nums);

This is more of a programmatic question which is seen at beginner level. The intent is to check the knowledge of applicant in Collection utility classes. For now, lets learn that there are two utility classes in Collection framework which are mostly seen in interviews i.e. Collections and Arrays.

Collections class provides some static functions to perform specific operations on collection types. And Arrays provide utility functions to be performed on array types.

//String array
String[] words = {"ace", "boom", "crew", "dog", "eon"};
//Use Arrays utility class
List wordList = Arrays.asList(words);
//Now you can iterate over the list
Please not that this function is not specific to String class, it will return List of element of any type, of which the array is. e.g.

//String array
Integer[] nums = {1,2,3,4};
//Use Arrays utility class
List numsList = Arrays.asList(nums);



Discussion

No Comment Found