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);
}
}
Java常用的指令
最新推荐文章于 2024-12-28 09:25:47 发布
1166

被折叠的 条评论
为什么被折叠?



