Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Options for initializing a string array [duplicate]

What options do I have when initializing string[] object?

like image 239
mrblah Avatar asked Oct 01 '09 16:10

mrblah


People also ask

How do you initialize a string array?

Initialization of Arrays of Strings: Arrays can be initialized after the declaration. It is not necessary to declare and initialize at the same time using the new keyword. However, Initializing an Array after the declaration, it must be initialized with the new keyword. It can't be initialized by only assigning values.

How can we declare and initialize array of strings in C?

A more convenient way to initialize a C string is to initialize it through character array: char char_array[] = "Look Here"; This is same as initializing it as follows: char char_array[] = { 'L', 'o', 'o', 'k', ' ', 'H', 'e', 'r', 'e', '\0' };

How do you check if a string is repeated in an array?

Check if a String is contained in an Array using indexOf # We used the Array. indexOf method to check if the string two is contained in the array. If the string is not contained in the array, the indexOf method returns -1 , otherwise it returns the index of the first occurrence of the string in the array.

How do you declare a string array in Java?

There are various ways in which you can declare an array in Java: float floatArray[]; // Initialize later int[] integerArray = new int[10]; String[] array = new String[] {"a", "b"};


1 Answers

You have several options:

string[] items = { "Item1", "Item2", "Item3", "Item4" };  string[] items = new string[] {   "Item1", "Item2", "Item3", "Item4" };  string[] items = new string[10]; items[0] = "Item1"; items[1] = "Item2"; // ... 
like image 159
Will Eddins Avatar answered Sep 20 '22 17:09

Will Eddins