logo
  • 教程列表
  • SO官方文檔
  • 宇宙飛船運算子
    • Spaceship 運算子進行自定義排序
    • 基本用法
    • 使用 Comparator 和 SortedSet
  1. StackOverflow 文件
  2. groovy 教程
  3. 宇宙飛船運算子
  4. 使用 Comparator 和 SortedSet

使用 Comparator 和 SortedSet

Created: November-22, 2018

Comparator cmp = [ compare:{ a, b -> a <=> b } ] as Comparator
def col = [ 'aa', 'aa', 'nn', '00' ]
SortedSet sorted = new TreeSet( cmp )
sorted.addAll col
assert '[00, aa, nn]' == sorted.toString()
  • 基本用法

Copyright © 2018. All right reserved

tastones.com 备案号:鲁ICP备18045372号-1

  • 關於本站
  • 免責聲明