Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert string[] to ArrayList?

Tags:

I have an array of strings. How can I convert it to System.Collections.ArrayList?

like image 972
Sergey Avatar asked Nov 09 '09 15:11

Sergey


People also ask

Can we convert String [] to String?

So how to convert String array to String in java. We can use Arrays. toString method that invoke the toString() method on individual elements and use StringBuilder to create String. We can also create our own method to convert String array to String if we have some specific format requirements.

How do I convert a String to an ArrayList in java?

1) First split the string using String split() method and assign the substrings into an array of strings. We can split the string based on any character, expression etc. 2) Create an ArrayList and copy the element of string array to newly created ArrayList using Arrays. asList() method.

Is String and String [] same in java?

String[] and String... are the same thing internally, i. e., an array of Strings. The difference is that when you use a varargs parameter ( String... ) you can call the method like: public void myMethod( String... foo ) { // do something // foo is an array (String[]) internally System.


1 Answers

string[] myStringArray = new string[2];
myStringArray[0] = "G";
myStringArray[1] = "L";

ArrayList myArrayList = new ArrayList();
myArrayList.AddRange(myStringArray);
like image 87
Kyle B. Avatar answered Oct 02 '22 07:10

Kyle B.