`

Sorting List in Groovy Language

    博客分类:
  • Java
阅读更多
//Sort Object by its Field
// Create a object under file name Student.groovy
class Student{
    int id
    String name
}
 
//Explanation
def studentList = [ new Student(id: 2, name: 'Beta'),
            new Student(id: 1, name: 'Charley'),
            new Student(id: 3, name: 'Alpha')
          ]
          
//output will be Charley, Beta, Alpha
studentList.sort{ it.id }
studentList.each{print it.name+' '}
println() 
//output will be Alpha, Beta, Charley
studentList.sort{ it.name }
studentList.each{print it.name+' '}           
分享到:
评论

相关推荐

    sorting numbers in 8086 assembly.zip

    在给定的"sorting numbers in 8086 assembly.zip"压缩包中,我们有以下几个关键文件: 1. `sort.asm`:这是主要的源代码文件,其中包含了实现排序算法的8086汇编语言代码。在这个文件中,程序员可能会使用经典的...

    poj 1007 DNA Sorting

    DNA Sorting Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 34868 Accepted: 13480 Description One measure of ``unsortedness'' in a sequence is the number of pairs of entries that are ...

    Algorithms in C, Parts 1-4_ Fundamentals, Data Structures, Sorting, Searching

    《算法在C语言中,第一至四部分:基础,数据结构,排序和搜索》是由Robert Sedgewick撰写的一本专注于算法学习的书籍。此书分为四个部分,分别涉及算法的基础概念、数据结构、排序算法和搜索技术,是一本对于IT专业...

    dianti.rar_SORTING IN VHDL_vhdl电梯三层

    5. **排序算法**:标签"sorting_in_vhdl"表明在程序中使用了某种排序算法,如冒泡排序、选择排序或快速排序,来确定电梯的行驶路径。这通常涉及到比较和交换操作,确保电梯按照乘客请求的顺序停靠。 6. **显示逻辑*...

    NGUI Sorting Layer script

    "NGUI Sorting Layer script" 是针对NGUI的一个特定优化,用于解决UI元素的绘制顺序问题,使得开发者能够更灵活地控制界面元素的前后层次关系。 在Unity中,Sorting Layer是一个重要的概念,它允许我们将游戏对象...

    PowerBuilder Sorting In Datawindow

    在`powerbuilder_dw_sorting.txt`文件中,可能包含了关于如何在代码中实现DataWindow排序的具体示例。例如,使用SetTransObject和ExecuteTrans来执行带有ORDER BY子句的SQL查询,或者使用SetSort和Refresh方法实现...

    sorting算法

    本文将详细探讨"Insertion Sorting"、"Swap Sorting"(可能指的是Bubble Sort或Counting Sort,因为通常没有直接称为"Swap Sorting"的算法)、"Selection Sorting"这三种常见的排序算法,以及在实现这些算法时可能...

    Algorithms in C++, Parts 1-4: Fundamentals, Data Structures, Sorting, Searching

    9. **First-Class ADTs**: This section introduces the concept of first-class ADTs, which are ADTs that can be treated like any other object in the language. This feature allows for greater flexibility ...

    Implementing Sorting in Databases (2006)-计算机科学

    Implementing Sorting in Database SystemsGOETZ GRAEFEMicrosoftMost commercial database systems do (or should) exploit many sorting techniques that are publicly known, but not readily available in the ...

    Problem Solving in Data Structures & Algorithms Using C++

    You are not an expert in C++ language, but you are well familiar with concepts of references, functions, arrays and recursion. In the start of this book, we will be revising the C++ language ...

    js-sorting-algorithm

    ### 十大经典排序算法详解 #### 排序算法概述 排序算法是计算机科学中一个重要的组成部分,广泛应用于数据处理和信息检索系统中。根据排序过程中数据存储位置的不同,可以将排序算法分为内部排序和外部排序。...

    Problem.Solving.in.Data.Structures.and.Algorithms.Using.Cplusplus.epub

    You are not an expert in C++ language, but you are well familiar with concepts of references, functions, arrays and recursion. In the start of this book, we will be revising the C++ language ...

    bubble sorting冒泡算法,c++

    随机数列,可控制上下界线。冒泡算法,c++,bubble sorting

    POJ1094-Sorting It All Out

    【标题】"POJ1094-Sorting It All Out" 是一道来自北京大学在线判题系统POJ(Problem Set)的编程题目。这道题目主要考察的是排序算法的应用与优化,旨在提高参赛者的算法设计和实现能力。 【描述】"北大POJ1094-...

    selection sorting选择排序,c++

    生成一个可以控制上下界限的随机数列,并使用选择排序selection sorting算法对其排序。

    Algorithms in C++, Parts 1–4 Fundamentals, Data Structure, Sorting, Searching, Third Edition

    STL包含容器(如vector、list、set和map)、迭代器、算法和函数对象,为实现和分析算法提供了强大的工具。 通过阅读这本书,读者不仅能学习到一系列算法的实现,还能掌握如何在实际问题中选择和优化算法,以及如何...

    dierwenw.zip_In Time_Parallel sorting_compressor_large scale pro

    Genetic algorithm matlab code for large-scale compressor blades parallel sorting problem and is very time-saving in many aspects.it is very good.

    sound-of-sorting-0.6-win32

    《声音中的排序:sound-of-sorting-0.6-win32》 在计算机科学的世界里,数据结构与算法是至关重要的基石,它们是程序设计的灵魂。"sound-of-sorting-0.6-win32"是一个专为Windows 32位操作系统设计的软件,它为学习...

    poj dna sorting

    poj dna sorting 问题,研究的ac coderrrrrrr

    External sorting

    找了很久的外排序,不过现在很多都用数据库代替了,对提高代码功力还是有用的.

Global site tag (gtag.js) - Google Analytics