How to combine two different length lists in kotlin?
问题 I want to combine two different length lists. For example; val list1 = listOf(1,2,3,4,5) val list2 = listOf("a","b","c") I want to result like this (1,"a",2,"b",3,"c",4,5) Is there any suggestion? 回答1: You may use the .zip function for that list1.zip(list2){ a,b -> listOf(a,b)}.flatten() The only problem is that it will only process elements, with both sets, so if (like in the example) let's have different size - it will not work The alternative could be to add specific markers and filter