*/
val takeLast= list.takeLast(4)

/**

  • 从第一项开始判断,直到不符合就返回,返回符合的前几项数据
  • Returns a list containing first elements satisfying the given [predicate].
  • []
    */
    val takeWhile= list.takeWhile { it>4 }
  • 映射操作符

private val list= listOf(0,1,2,3,4,5,4,3,2,1,0,-1)

/**

  • 返回满足条件的集合
  • Returns a list containing the results of applying the given [transform] function
  • to each element in the original collection.
  • [false, false, false, true, true, true, true, true, false, false, false, false]
    */
    val map=list.map { it>2 }

/**

  • 返回特定函数后的集合,参数是Iterable类型,
  • Returns a single list of all elements yielded from results of [transform]
  • function being invoked on each element of original collection.
  • [0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 4, 5, 3, 4, 2, 3, 1, 2, 0, 1, -1, 0]
    */
    val flatMap=list.flatMap { listOf(it, it + 1) }

/**

  • 根据函数将集合分组,返回map类型对象
  • Groups elements of the original collection by the key returned by the given [keySelector] function
  • applied to each element and returns a map where each group key is associated with a list of corresponding elements.
  • The returned map preserves the entry iteration order of the keys produced from the original collection.
  • {false=[0, 1, 2, 3, 3, 2, 1, 0, -1], true=[4, 5, 4]}
  • @sample samples.collections.Collections.Transformations.groupBy
    */
    val groupBy=list.groupBy {value-> value>3 }

/**

  • 返回一个集合,通过 角标和值 来生成
  • Returns a list containing the results of applying the given [transform] function
  • to each element and its index in the original collection.
  • @param [transform] function that takes the index of an element and the element itself
  • and returns the result of the transform applied to the element.
  • [0, 1, 2, 3, 4, 5, 4, 3, 2, 1, 0, -1]
    */
    val mapIndexed=list.mapIndexed { index, value ->value}

/**

  • 返回一个每一个非null元素根据给定的函数转换所组成的List
  • Returns a list containing only the non-null results of applying the given [transform] function
  • to each element in the original collection.
  • [0, 2, 4, 6, 8, 10, 8, 6, 4, 2, 0, -2]
    /
    val mapNotNull=list.mapNotNull { it
    2 }
  • 元素操作符

private val list= listOf(0,1,2,3,4,5,6,4,3,2,1,0,-1)

//如果指定元素可以在集合中找到,则返回true。
val contains=list.contains(2)

/**

  • 返回给定index对应的元素,如果index数组越界则会 抛出IndexOutOfBoundsException
  • Returns an element at the given [index] or throws an [IndexOutOfBoundsException] if the [index] is out of bounds of this collection.
  • 2
    */
    val elementAt=list.elementAt(2)

/**

  • 返回给定index对应的元素,如果index数组越界则会根据给定函数返回默认值,第二个参数default,lamdba表达式
  • Returns an element at the given [index] or the result of calling the [defaultValue]
  • function if the [index] is out of bounds of this collection.
  • 2
    */
    val elementAtOrElse=list.elementAtOrElse(2){“error”}

/**

  • 返回给定index对应的元素,如果index数组越界则会 返回null
  • Returns an element at the given [index] or null if the [index] is out of bounds of this list.
  • null
    */
    val elementAtOrNull=list.elementAtOrNull(19)

/**

  • Returns first element.
  • @throws [NoSuchElementException] if the list is empty.
  • 0
    */
    val first=list.first()

/**

  • 返回符合给定函数条件的第一个元素,没有回抛异常
  • Returns the first element matching the given [predicate].
  • @throws [NoSuchElementException] if no such element is found.
  • 4
    */
    val first2=list.first { it>3 }

/**

  • 返回符合给定函数条件的第一个元素,如果没有符合则返回null
  • Returns the first element matching the given [predicate], or null if element was not found.
  • null
    */
    val firstOrNull=list.firstOrNull { it>9 }

/**

  • 返回指定元素的第一个index,如果不存在,则返回-1
  • Returns the index of the first occurrence of the specified element in the list, or -1 if the specified
  • element is not contained in the list.
  • 3
    */
    val indexOf=list.indexOf(3)

/**

  • 返回第一个符合给定函数条件的元素的index,如果没有符合则返回-1
  • Returns index of the first element matching the given [predicate], or -1 if the list does not contain such element.
  • 0
    */
    val indexOfFirst=list.indexOfFirst { it%3==0 }

/**

  • 返回最后一个符合给定函数条件的元素的index,如果没有符合则返回-1
  • Returns index of the last element matching the given [predicate], or -1 if the list does not contain such element.
  • 11
    */
    val indexOfLast=list.indexOfLast { it%3==0 }

/**

  • 返回符合给定函数条件的最后一个元素,没有抛异常
  • Returns the last element matching the given [predicate].
  • @throws [NoSuchElementException] if no such element is found.
  • 6
    */
    val last=list.last { it>4 }

/**

  • 返回指定元素的最后一个index,如果不存在,则返回-1
  • Returns the index of the last occurrence of the specified element in the list, or -1 if the specified
  • element is not contained in the list.
  • 8
    */
    val lastIndexOf=list.lastIndexOf(3)

/**

  • 返回符合给定函数条件的最后一个元素,如果没有符合则返回null
  • Returns the last element matching the given [predicate], or null if no such element was found.
  • null
    */
    val lastOrNull=list.lastOrNull { it>8 }

/**

  • 返回符合给定函数的单个元素,如果没有符合或者超过一个,则抛出异常
  • Returns the single element matching the given [predicate], or throws exception if there is no or more than one matching element.
  • 6
    */
    val single=list.single { it>5 }

/**

  • 返回符合给定函数的单个元素,如果没有符合或者超过一个,则返回null
  • Returns the single element matching the given [predicate], or null if element was not found or more than one element was found.
  • null
    */
    val singleOrNull=list.singleOrNull { it>8 }
  • 生产操作符

private val list1= listOf(0,1,2,3,4,5)
private val list2= listOf(4,5,2,1,5)

/**

  • Returns a list of pairs built from elements of both collections with same indexes. List has length of shortest collection.
  • [(0, 4), (1, 5), (2, 2), (3, 1), (4, 5)]
    */
    val zip= list1.zip(list2)

/**

  • Returns a list of values built from elements of both collections with same indexes using provided [transform]. List has length of shortest collection.
  • [4, 6, 4, 4, 9]
    */
    val zip2= list1.zip(list2){it1,it2->it1+it2}

//[(0, 0), (1, 1), (2, 2), (3, 3), (4, 4), (5, 5)]
val zip4= list1.zip(list1+list2)

//[0, 2, 4, 6, 8, 10]
val zip3= list1.zip(list1+list2){it1,it2->it1+it2}

/**

  • Returns a pair of lists, where
  • first list is built from the first values of each pair from this collection,
  • second list is built from the second values of each pair from this collection.
  • ([1, 3, 7], [3, 4, 8])
    */
    val unzip= listOf(Pair(1,3),Pair(3,4),Pair(7,8)).unzip()

/**

  • 把一个给定的集合分割成两个,第一个集合是由原集合每一项元素匹配给定函数条件返回true的元素组成,
  • 第二个集合是由原集合每一项元素匹配给定函数条件返回false的元素组成
  • Splits the original collection into pair of lists,
  • where first list contains elements for which [predicate] yielded true,
  • while second list contains elements for which [predicate] yielded false.
  • ([0, 2, 4], [1, 3, 5]) value
    */
    val partition= list1.partition { it%2==0 }

自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。

深知大多数初中级安卓工程师,想要提升技能,往往是自己摸索成长,但自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!

因此收集整理了一份《2024年最新Android移动开发全套学习资料》送给大家,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。
img
img
img
img

由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频
如果你觉得这些内容对你有帮助,可以添加下面V无偿领取!(备注Android)
img

写在最后

对程序员来说,很多技术的学习都是“防御性”的。也就是说,我们是在为未来学习。我们学习新技术的目的,或是为了在新项目中应用,或仅仅是为了将来的面试。但不管怎样,一定不能“止步不前”,不能荒废掉。

![
[]


文章以下内容会给出阿里与美团的面试题(答案+解析)、面试题库、Java核心知识点梳理等,需要这些文档资料的,直接点击我的GitHub免费领取~

d9b84cc0ef9.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

[外链图片转存中…(img-LcdhUNbj-1711189185726)]
[外链图片转存中…(img-jN1npcUY-1711189185727)]

文章以下内容会给出阿里与美团的面试题(答案+解析)、面试题库、Java核心知识点梳理等,需要这些文档资料的,直接点击我的GitHub免费领取~

Logo

北京人形旗下天工造物具身智能开源社区,聚焦具身天工与慧思开物两大平台

更多推荐