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")
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.
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 ...
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.
String[] ar = new String[size]; Arrays. fill(ar,"");
You can use arrayOf(), as in
val literals = arrayOf("January", "February", "March")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With