+ 1
Kotlin custom value arrays
Well, in C++ we have library <vector> or dynamic memory It helps us to create an array with N elements (like, if we input in console N, we can continue to enter the values until the number of values reaches N) Is there an analog of them in Kotlin?
6 Respuestas
0
Please, what do you mean by this question ? Ask it in an other way, because I think I can help you
0
VCoder well, if you are into C++, you may know something about vectors – arrays, which can hold as many elements as you want without declaring a size of array. For example:
#inlude <vector>
using namespace std;
int main(){
vector<int>a;
a.push_back(3); //now it has 1 element
int n;
cin>>n;
int b[n];
b[0]=3; //error, n is non-constant arguement
return 0;
}
Vectors can hold more values than the common arrays without declaring a size, that is the reason why I am asking
0
And you want the thing but with kotlin ? Is it right ?
0
VCoder no, no, I want to make an array in Kotlin, which hold integrals and can ardd several numbers from console
0
So you want an array where you can do special manipulations like adding and removing elements ?
0
Here is a code where you can give multiple integer inputs and each of them will be added dynamically to the list (in Kotlin) :
fun main(args: Array<String>) {
val arr = mutableListOf<Int>()
var input: String? = readLine()
while(input != null) {
arr.add(input.toInt())
input = readLine()
}
println(arr)
}
I am making a serie of tutorials of things related to coding and Kotlin is in the list and I noticed that there is a lot of cool things that sololearn didn't implemented in their Kotlin course, so if you follow me, I will be able to give you coding tricks and also learn you Android Dev with Java and Kotlin
You can check this page and comment what you want to learn :
https://code.sololearn.com/WIb425hnGqfl/?ref=app