Convert String array to ArrayList

To convert a String array to an ArrayList in Java, you can use the following steps:

  1. Import the necessary classes:
import java.util.ArrayList;
import java.util.Arrays;
  1. Create a String array:
String[] stringArray = {"item1", "item2", "item3"};
  1. Use the asList() method of the Arrays class to convert the String array to a List:
List<String> list = Arrays.asList(stringArray);
  1. Create an ArrayList from the List:
ArrayList<String> arrayList = new ArrayList<>(list);

Alternatively, you can use the addAll() method of the ArrayList class to add all the elements of the String array to an ArrayList:

ArrayList<String> arrayList = new ArrayList<>();
arrayList.addAll(Arrays.asList(stringArray));

I hope this helps. Let me know if you have any questions.