fun getUpperFruits() { val list = listOf("Apple", "Banana", "Orange", "Pear", "Grape", "Watermelon") val newlist = list.map { it.toUpperCase() } for (fruit in newlist) { println(fruit) } } 1. 2. 3. 4. 5. 6. 7. filter: Example: fun filterFruits() {...
Here is an example fun main() { val map = HashMap<String, String>() map["1"] = "one" map["2"] = "two" map["3"] = "three" map["4"] = "four" map["5"] = "five" val iterator = map.keys.iterator() while (iterator.hasNext()) { val key = iterator.next() val value...
valmap1=mapOf(1to"one",2.to("two"),Pair(3,"three")// new Pair(3, "three"))println(map1)valhashMap=hashMapOf(1to"one",2to"two",3to"three")println(hashMap)listOf(1,2,3,4,5)subtractlistOf(2,3)listOf(1,2,3,4,5)unionlistOf(6,7)listOf(1,2,3,4,5)ziplistOf(2,3...
B> = Pair(this, that) //我们仿照它写一个 public infix fun <A,B> A.with(that: B): Pair<A,B> = Pair(this,that) fun main() { val map = mapOf("Apple" with 1,"Banana" with 2,"Orange" with 3,"Pear" with 4,"Grape" with 5) } ...
//委托者类Example,这里将会将其属性计算委托给Delegate实现classExample{//属性委托的语法,同上一个章节阐述的一样,使用by关键字修饰即可。vartest:StringbyDelegate()}//测试类classMain{companionobject{@JvmStaticfunmain(args:Array<String>){valexample=Example()//生成一个委托者对象println(example.test)//这里...
Example@433c675d, 这里委托了 p 属性 标准委托 Kotlin 的标准库中已经内置了很多工厂方法来实现属性的委托。 延迟属性 Lazy lazy() 是一个函数, 接受一个 Lambda 表达式作为参数, 返回一个 Lazy <T> 实例的函数,返回的实例可以作为实现延迟属性的委托: 第一次调用 get() 会执行已传递给 lazy() 的 lamda ...
Example@433c675d 的 p 属性赋值为 RunoobExample@433c675d, 这里委托了 p 属性 可观察属性 Observable @[Kotlin 的标准库中已经内置了很多工厂方法来实现属性的委托。] import kotlin.properties.Delegates class User { var name: String by Delegates.observable("初始值") { prop, old, new -> println("...
首先在 mediapipe/examples/android/src/java/com/google/mediapipe/apps/aar_example 里创建一个 BUILD 文件, 并把一下内容添加到文本文件里. load("//mediapipe/java/com/google/mediapipe:mediapipe_aar.bzl", "mediapipe_aar") mediapipe_aar( name = "hand_tracking_aar", calculators = ["//mediapipe/grap...
flatMap()– transformation and flattening So, the logic implemented byflatMap()can be written withmap()andflatten()too. In other words:flatMap()is equivalent tomap()and thenflatten(). An example might help us quickly understand the differences and relations among these three functions: ...
valgoogleMap=//...valsydney=LatLng(-33.852,151.211)valmarker=googleMap.addMarker { position(sydney) title("Marker in Sydney") } Accessing aGoogleMapinstance can be retrieved using coroutines vs. traditional the callback mechanism. The example here demonstrates how you can use this feature alongs...