zoukankan      html  css  js  c++  java
  • groovy集合

    groovy集合可以直接在语言中使用,因为它默认已经导入包了。
    不需要初始化对象,也不需要专门的类。
    集合是groovy语言本地成员。Groovy语法提供了本地列表和相应的映射。
    每个Groovy集合都是java.util.Collection 或者 java.util.Map 实例。
    groovy使用了许多方法向groovy集合添加元素。

    **
     * Groovy集合
     * Created by Jxy on 2018/12/19 10:27
     * A,验证范围类型也是java.util.List  的一个实例
     * B,集合
     */
    class Demo2 {
        static void  main(args){
    
            def range = 0..5
            println(range.class)
            assert range instanceof List
            /*
            groovy集合添加元素
             */
            def coll = ["Groovy", "Java", "Ruby"]
            coll.add("Python")
            coll << "aug"
            coll[5] = "Perl"
            println(coll)
            /*
            循环遍历集合元素
             */
            for (i in 0..<coll.size()){
                print(coll[i]+" ")
            }
            /*
            拿到第四个元素
             */
            assert coll[3] == "Python"
            assert  coll instanceof Collection
            assert coll instanceof ArrayList
    
            /*
            groovy集合操作集合
             */
            def list = [1,2,3,4]
            assert list + 5 == [1,2,3,4,5]
            assert list - [2,3] == [1,4]
    
        }
    }

    运行结果:

    class groovy.lang.IntRange
    [Groovy, Java, Ruby, Python, aug, Perl]
    Groovy Java Ruby Python aug Perl 
    Process finished with exit code 0
  • 相关阅读:
    nginx部分功能配置备忘
    mysql 截取数据 组合排序
    java实现排列组合
    每日记载内容总结48
    http请求转换为https请求
    每日记载内容总结47
    rabbitmq 基本操作
    redis免密登录被入侵解决方式
    支付宝支付sign_type从RSA到RSA2遇到的问题
    Java面试题2
  • 原文地址:https://www.cnblogs.com/jsersudo/p/10150408.html
Copyright © 2011-2022 走看看