The first question is: If ‘chunks’ is a sequence of strings? How would you define it?
The second question is: How can I get the first element of each string [one, two, three, four]? // o, t, t, f
Should I create listOf for each and then take the first element out of them?
I don’t really understand your question here. Maybe someone else can help you with this or you could try to explain again what you are asking for. Do you want to know what chunked does? It splits a long list into a list of shorter lists. So if you call someList.chunked(3) the first 3 elements will end up in the first list, the next 3 elements in a second list and so on.
Hey. I am asking about the val chunks. Is this variable a sequence or list etc?
"one two three four".split(' ').map { it[0] }
If I understand well it returns the first element which is ‘o’, however, I am looking for something that will allow me to take the first letter of each word, not only the first element. Is it any more accurate?
If that doesn’t help, maybe try to explain what you are trying to create in a bit more detail. I could endlessly show you code examples of how to solve a specific subproblem, but unless you fully understand why any of that code works it wont help you solve your problem.
Thanks for your help Wasabi. I’m fresh to this. I’m doing play.kotlin but many things are not explained there, some things are just used without absolute explanation. So what I’m doing is I am going through Kotlin documentation step by step plus play.kotlin.
I am not really trying to create anything. My mind throws me some questions that I would like to know the answers for. Kotlin documentation is rich but it’s easy not stay on track if you fresh.
Okay: println(listOf[0]) // [1,2] - is that correct? That is going to be the outcome right? I suppose it doesn’t make any sense now to access just ‘2’ once we grouped them but I wonder if its possible after .chunked
If you want the 2nd element of the first chunk you can do println(chunks[0][1]) // [2]
there’s nothing special about that, you have a list of lists and you’re getting the 2nd element of the 1st list.