println("test length func :${getObjectLength("How long do i have, please?")}"); //geLength 会出现会重写的情况,应该是自动倒入了某些系统的类导致的。 var list= listOf<String>("hello","apple","fuck","qssq"); var list1= listOf<Any>("hello","apple","fuck","qssq",1,33,3); var list2= listOf("any ,or not any","xxx","ddd","dd",1,33,3); for(item in list){ println("list current Item:${item}"); } for(index in list.indices){ println(" list current index :${index},item:${list.get(index)} items:${list[index]}"); } println("test list1 length:${list1.size}")
for(index in list2.indices){ println(" list current index :${index},item:${list2.get(index)} items:${list2[index]}");
//jugde list is contain str //判断hello1是否等于list集合里面的某一个字符串(非关键字包含) var list= listOf<String>("hello","apple","fuck","qssq"); if("hello" in list){ println("hello at list "); }else{ println("hello not at list ");
} //jugde index at
if(1 in list.indices){ println("1 at list.indiices") }else{ println("1 not at list.indiices")
} if(5 in 0..list.lastIndex){ println("1 at list 0-${list.lastIndex}"); }else{
println("1 not at list 0-${list.lastIndex}"); }
1 2 3 4 5 6 7 8
for (x in 12 downTo 0 step 3) {//print 12 9 6 3 0 println("downTo "+x) }
for (x in 0..12 step 2) { println("current:"+x)//0 2 4 6 xx 12 }
map的打印和创建
1 2 3 4 5 6 7 8 9 10 11
var map= mapOf<Any,Any>(Pair("qssq","694886526"),Pair("qssq666","1234455"),Pair("qssqa","bbbbbbb")); for (entry in map) { println("test "+entry.key+",entry.value:"+entry.value);
} map.forEach { t, u -> println("map.forEach key $t value $u"); } for ((k, v) in map) { println("key:$k ->value: $v") }