0

How do I place an Array like a row in a List?

For Example:

 string[] Myarray = new string[] {"A","B", "C"};
 List<string> MyList = new List<string>() { Myarray[0], Myarray[1], Myarray[2] };
anonymous
  • 536
  • 3
  • 11
  • 29
Joshua
  • 43
  • 3

1 Answers1

0
List<String> strings = Arrays.asList(new String[]{"one", "two", "three"});

This is a list view of the array, the list is partly unmodifiable, you can't add or delete elements. But the time complexity is O(1).

If you want a modifiable a List:

List<String> strings = 
     new ArrayList<String>(Arrays.asList(new String[]{"one", "two", "three"}));

This will copy all elements from the source array into a new list (complexity: O(n))