Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java - How do I make a String array with values?

I know how to make an empty array, but how do I make a String array with values from the start?

like image 954
Gray Adams Avatar asked Dec 18 '11 04:12

Gray Adams


People also ask

How do you declare a string array of values?

You can also initialize the String Array as follows:String[] strArray = new String[3]; strArray[0] = “one”; strArray[1] = “two”; strArray[2] = “three”; Here the String Array is declared first. Then in the next line, the individual elements are assigned values.


1 Answers

You could do something like this

String[] myStrings = { "One", "Two", "Three" }; 

or in expression

functionCall(new String[] { "One", "Two", "Three" }); 

or

String myStrings[]; myStrings = new String[] { "One", "Two", "Three" }; 
like image 56
Alex Gitelman Avatar answered Oct 24 '22 19:10

Alex Gitelman