Arrays.stream()、switch、str.charAt(index)、Arrays.sort(array)

Arrays.stream()

Arrays.stream()将字符串数组转换为流

switch的使用:

switch(a){
    case 0 : num/2; break;
    case 1 : num-=1; break;
}

str.charAt(index)

var str = new String("This is string"); 
console.log("str.charAt(0) is:" + str.charAt(0)); 
console.log("str.charAt(1) is:" + str.charAt(1)); 
console.log("str.charAt(2) is:" + str.charAt(2)); 
console.log("str.charAt(3) is:" + str.charAt(3)); 
console.log("str.charAt(4) is:" + str.charAt(4)); 
console.log("str.charAt(5) is:" + str.charAt(5));

//结果
str.charAt(0) is:T 
str.charAt(1) is:h 
str.charAt(2) is:i 
str.charAt(3) is:s 
str.charAt(4) is:
str.charAt(5) is:i

进阶用法

s1.charAt(i)返回s1 i的第th个字符String. 假设此String仅包含小写字母(即'a'到'z'),s1. //charAt(i)-'a'将字符'a'映射到索引0,将'b'映射到索引1,依此类推('z'映射到索引25) .

int x = s2.charAt(right) - 'a';

这个循环所做的就是计算字母的频率

它表示字符串s2,从right开始减去'a',就相当于s2.charAt(right)=b,类似于'b'-'a'=1

Arrays.sort(array);

Arrays.sort(array);//会检查数组个数大于286且连续性好就使用归并排序,若小于47使用插入排序,其余情况使用双轴快速排序

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值