Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

string array literal ? How do I code it simply?

Tags:

arrays

kotlin

Though that may be a silly question, I can't figure out how to declare an array literal grouping some string literals.

For example, let's assume I want the java array ["January", "February", "March"]. How can I translate this into the latest kotlin version (today, 12.0.0)?

What have I tried?

stringArray("January", "February", "March") 
like image 999
loloof64 Avatar asked Jun 01 '15 16:06

loloof64


People also ask

How do you make a string array?

The String Array is initialized at the same time as it is declared. 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.

How do you represent an array of strings?

Syntax. datatype name_of_the_array [ ] = { Elements of array }; char str_name[8] = "Strings"; Str_name is the string name and the size defines the length of the string (number of characters). A String can be defined as a one-dimensional array of characters, so an array of strings is two –dimensional array of characters ...

What is array literal syntax?

Array literals An array literal is a list of zero or more expressions, each of which represents an array element, enclosed in square brackets ( [] ). When you create an array using an array literal, it is initialized with the specified values as its elements, and its length is set to the number of arguments specified.

How do I make a string array in Python?

String[] ar = new String[size]; Arrays. fill(ar,"");


1 Answers

You can use arrayOf(), as in

val literals = arrayOf("January", "February", "March") 
like image 120
Hadi Hariri Avatar answered Sep 18 '22 18:09

Hadi Hariri