Java常用的指令

package bool;

import java.util.Arrays;

public class Test {
	public static void main(String[] args) {
		
		String s = "abcabc";
		String ss = "ABCABC";
		
//		获取指定位置的字符
		char c = s.charAt(0);
		System.out.println(c);
		
//		忽略大小写的比较
		System.out.println(s.equalsIgnoreCase(ss));

//		将字符串全部转换成大写
		System.out.println(s.toUpperCase());
		
//		将字符串全部转换成小写
		System.out.println(ss.toLowerCase());
		
//		按自定字符切割字符串
		String[] split = s.split("b");
		
//		打印数组
		System.out.println(Arrays.toString(split));
		
//		查找字符在字符串中第一次出现的位置,没有就返回-1
		int i = s.indexOf("b");
		System.out.println(i);
		
//		从下标2切割直到结尾
		String sub = s.substring(2);
		System.out.println(sub);
		
//		从下标2开始到下标4前结束,下标4不包含在内
		String subs = s.substring(2,4);
		System.out.println(subs);
		
//		确认字符串长度
		int len = s.length();
		System.out.println(len);
		
//		Math
//		Java的Math类封装了很多与数学有关的属性和方法。
//		Abs - 求绝对值
//		Max/min - 最大值最小值
//		random() - 生成一个0-1之间的随机数
		double j = Math.random();
		System.out.println(j);
	}
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值