Groory(二) 字符串String+集合Collection篇---极速入门总结

本文主要介绍了Groovy中的字符串常用操作以及集合的使用,包括Collection的基本特性、List和Map的总结,特别是Map的键值对定义及常用操作,同时讲解了List与Map结合闭包的应用。
摘要由CSDN通过智能技术生成


一、字符串常用用法

<pre class="java" name="code">/**
 * 这里只总结一些与java不同的的用法,但是又比较常用的API
 */
/**
 *  "  '  ' "的用法
 */
String c = "'Hello Triple" + "Multiple lines'";//print 'Hello TripleMultiple lines'						/**
 *索引用法
 */
String sample = "Hello world";
println(sample[4]); // Print the 5 character in the string :o

//Print the 1st character in the string starting from the back
println(sample[-1]);// print d
println(sample[1..2]);//Prints a string starting from Index 1 to 2: el
println(sample[4..2]);//Prints a string starting from Index 4 back to 2 : oll							/**
 * 字符串连接
 */
String a = "Hello";
String b = "World";
println(a + b); //print HelloWorld
println( a.concat(b))//print HelloWorld

/**
 * 在一个字符串内匹配正则表达式
 */
String s = "He5lloW2or3ld";
s.eachMatch("\\d") {
    ch -> println ch //
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值