day08--String类的练习

This commit is contained in:
2025-12-30 14:13:14 +08:00
parent 0b27004642
commit 2a9aa1bd51
3 changed files with 40 additions and 0 deletions

View File

@@ -0,0 +1,25 @@
package com.inmind.string01;
/*
常用类_String的分割方法_split
public String[] split(String regex) 将此字符串按照给定的regex规则拆分为字符串数组
*/
public class Demo07 {
public static void main(String[] args) {
//定义一个字符串
String str = "1,22,张三";
//按,切割,获取对应的属性值; 注意:按什么分割,该字符串就不会出现
String[] values = str.split(",");
System.out.println(values);
for (int i = 0; i < values.length; i++) {
System.out.println(values[i]);
}
//扩展:将字符串转为学生对象!!
String str1 = "2,21,李四";
String[] strings = str1.split(",");
Student s = new Student(Integer.parseInt(strings[0]), Integer.parseInt(strings[1]), strings[2]);
System.out.println(s.getId());
System.out.println(s.getAge());
System.out.println(s.getName());
}
}

View File

@@ -0,0 +1,8 @@
package com.inmind.string01;
/*
常用类_String的练习_拼接字符串
定义一个方法,把数组{1,2,3}按照指定个格式拼接成一个字符串。格式参照如下:[值1#值2#值3]。
*/
public class Test08 {
}

View File

@@ -0,0 +1,7 @@
package com.inmind.string01;
/*
8.常用类_String的练习_统计字符个数
键盘录入一个字符串,统计字符串中大小写字母及数字字符个数
*/
public class Test09 {
}