根据id和id所在列表找到id的下一个和上一个id并返回!

private fun findAdjacentIds(knownId: Int, workIdList: List): Pair {
val sortedIdList = workIdList.sorted()
val index = sortedIdList.indexOf(knownId)
val prevId = if (index > 0) sortedIdList[index - 1] else -1
val nextId = if (index < sortedIdList.size - 1) sortedIdList[index + 1] else -1
return Pair(prevId, nextId)
}

你可能感兴趣的:(java)