in Education by
for all the examples on the internet i cant figure out when and how is kotlins let ran? if(phones.size == 0){ phones.add("") } return phones[0] so if phones list size is 0, we add empty string and return that instead. Now how would one do same with let ? phones.let { return "" } does this work with size 0, or do i have to have null list? do i need return keyword, if yes, where? is the above fun always going to return empty string? or just when phones is null? when is this let code block even ran? JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
Update: val cakes = listOf("carrot", "cheese", "chocolate") fun main(args: Array) { var cakesEaten = 0 while (cakesEaten < 3) { // 1 cakesEaten ++ val result = cakes?.let{ if(cakesEaten == 2) { "HeyLo" } else { 2 } } println("result value = $result") when(result) { is String -> println(" result variable is a String") is Int -> println(" result variable is Integer") } } } result value = 2 result variable is Integer result value = HeyLo result variable is a String result value = 2 result variable is Integer Original post If your 'phones' Object is a Nullable type, val result = phones?.let{ // this block runs only if phones object is not null // items can be accessed like it.size // expression result will be returned. no need to mention return. if(it.size == 0) { it.add("") it[0] } else it.size } result value will be either it[0] or it.size and its type will be Any. But if this the functionality you need you can check Markos solution.

Related questions

0 votes
    for all the examples on the internet i cant figure out when and how is kotlins let ran? if(phones ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 26, 2022 in Education by JackTerrance
0 votes
    we have RecyclerView with list of children songs, when you click on a song it takes you to another ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 9, 2022 in Education by JackTerrance
0 votes
    I'm using Kotlin to build a web service and I stumbled upon what I consider to be a strange ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 17, 2022 in Education by JackTerrance
0 votes
    How can I create array of buttons in android studio in Kotlin? I've created buttons with their ids ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 24, 2022 in Education by JackTerrance
0 votes
    What are the resolution steps when Burp does not intercept HTTPS requests? A)Toinstall Burp's CA certificate ... browser configuration. Select the correct answer from above options...
asked Nov 30, 2021 in Education by JackTerrance
0 votes
    Let X represent the difference between the number of heads and the number of tails obtained when a coin is tossed 6 ... values of X? Select the correct answer from above options...
asked Nov 25, 2021 in Education by JackTerrance
0 votes
    Let X denote the sum of the numbers obtained when two fair dice are rolled. Find the variance and standard deviation of X. Select the correct answer from above options...
asked Nov 25, 2021 in Education by JackTerrance
0 votes
    Let E1 and E2 be the events such that P (E1) = 1/3 and P (E2) = 3/5. Find: (i) P (E1 U E2), ... ∩ E2), when E1 and E2 are independent. Select the correct answer from above options...
asked Nov 21, 2021 in Education by JackTerrance
0 votes
    Let E1 and E2 be the events such that P(E1) = 1/3 and P(E2) = 3/5. Find: (i) P(E1∪ E2), when ... E2), when E1 and E2 are independent Select the correct answer from above options...
asked Nov 16, 2021 in Education by JackTerrance
0 votes
    Three defective bulbs are mixd with 7 good ones. Let X be the number of defective bulbs when 3 bulbs are drawn ... and variance of X. Select the correct answer from above options...
asked Nov 13, 2021 in Education by JackTerrance
0 votes
    How does dispatch_once manages to run only once?...
asked Nov 10, 2020 in Technology by JackTerrance
0 votes
    Bit of a noob question but I'm building an app in react native and to make development a bit ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 21, 2022 in Education by JackTerrance
0 votes
    This is my pretty simple C++/CMake .travis.yml env: global: # The next declaration is the ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 21, 2022 in Education by JackTerrance
0 votes
    Does a stochastic network will evolve differently each time it is run? (a) yes (b) no I have been ... Feedback Neural Networks of Neural Networks Please answer the above question....
asked Aug 30, 2022 in Education by JackTerrance
...