https://kotlinlang.org logo
#announcements
Title
# announcements
a

Ashutosh Panda

10/17/2019, 3:53 PM
Copy code
var numbers=arrayOf(
    11,
    12,
    13,
    14,
    15
)

var integer:MutableList<Int>=mutableListof()
        for(x in 0 until (numbers.size-1)) {
            integer[x]=numbers[x]
        }
for(element in integer) println("$element")
a

Animesh Sahu

10/17/2019, 3:59 PM
its
mutableListOf()
in line no 9
g

gian

10/17/2019, 4:00 PM
Also you need a space between > and =, otherwise it’s “greater than”
a

Animesh Sahu

10/17/2019, 4:00 PM
Tip: use val instead of var as suggested in kotlin docs since the number is never changed any instance
g

gian

10/17/2019, 4:01 PM
You are iterating
until size - 1
, so the last x is equal to
size - 2
a

Ashutosh Panda

10/17/2019, 4:01 PM
Hi thanks I am new to kotlin can you suggest me how to go through kotlin
g

gian

10/17/2019, 4:02 PM
either you use
..
instead of
until
or you use `until size`… Or even better
numbers.forEachIndexed
a

Ashutosh Panda

10/17/2019, 4:03 PM
One thing is using
Copy code
until
not right
g

gian

10/17/2019, 4:04 PM
until n
creates a range excluding
n
a

Animesh Sahu

10/17/2019, 4:04 PM
you'd have a ide such as intellij idea for debugging out compilation errors, it comes pretty handy in fixing those common mistakes, and font ligature with supported font such as fira code would help you for human rediability of code.
a

Ashutosh Panda

10/17/2019, 4:05 PM
what is this font ligature ...
and fira code
a

Animesh Sahu

10/17/2019, 4:07 PM
https://github.com/tonsky/FiraCode it help in grouping out the working operators, its just a font basically such as -> would become arrow and >= become greater than equal to symbol
e

Evan R.

10/17/2019, 4:35 PM
Also, if you’re trying to convert an array to a copied list you might try
numbers.toMutableList()
d

Dico

10/17/2019, 8:41 PM
You should be calling
integer.add
instead of
set
(aka [])