Skip to content

Commit 58038a7

Browse files
committed
conversion_string__转换字符串功能
1 parent 3737715 commit 58038a7

2 files changed

Lines changed: 64 additions & 2 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @由于个人水平有限, 难免有些错误, 还请指点:
33
* @Author: cpu_code
44
* @Date: 2020-07-12 12:03:11
5-
* @LastEditTime: 2020-09-12 20:35:45
5+
* @LastEditTime: 2020-09-12 20:36:51
66
* @FilePath: \java\README.md
77
* @Gitee: [https://gitee.com/cpu_code](https://gitee.com/cpu_code)
88
* @Github: [https://github.com/CPU-Code](https://github.com/CPU-Code)
@@ -126,7 +126,7 @@ java编程基础 面向对象 javaAPI 集合 IO GUI JD8C 多线程 网络编程
126126

127127
- [x] [string_compare__字符串比较](javaAPI/String/string_compare.java)
128128
- [x] [get_string__获取字符串功能](javaAPI/String/get_string.java)
129-
129+
- [x] [conversion_string__转换字符串功能](javaAPI/String/conversion_string.java)
130130

131131

132132
-----------------------
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
* @由于个人水平有限, 难免有些错误, 还请指点:
3+
* @Author: cpu_code
4+
* @Date: 2020-09-12 20:37:04
5+
* @LastEditTime: 2020-09-12 20:45:33
6+
* @FilePath: \java\javaAPI\String\conversion_string.java
7+
* @Gitee: [https://gitee.com/cpu_code](https://gitee.com/cpu_code)
8+
* @Github: [https://github.com/CPU-Code](https://github.com/CPU-Code)
9+
* @CSDN: [https://blog.csdn.net/qq_44226094](https://blog.csdn.net/qq_44226094)
10+
* @Gitbook: [https://923992029.gitbook.io/cpucode/](https://923992029.gitbook.io/cpucode/)
11+
*/
12+
package javaAPI.String;
13+
14+
public class conversion_string {
15+
public static void main(String[] args){
16+
//创建字符串对象
17+
String s = "cpucode";
18+
19+
// char[] toCharArray():把字符串转换为字符数组
20+
char[] chs = s.toCharArray();
21+
for(int i = 0; i < chs.length; i++){
22+
System.out.println(chs[i]);
23+
}
24+
System.out.println("---------");
25+
26+
// byte[] getBytes ():把字符串转换为字节数组
27+
byte[] bytes = s.getBytes();
28+
for(int i = 0; i < bytes.length; i++){
29+
System.out.println(bytes[i]);
30+
}
31+
System.out.println("--------");
32+
33+
// 替换字母为大写
34+
String str = "cpucode";
35+
String replace = str.replace("c", "C");
36+
37+
System.out.println(replace);
38+
System.out.println("--------");
39+
}
40+
}
41+
42+
/*
43+
c
44+
p
45+
u
46+
c
47+
o
48+
d
49+
e
50+
---------
51+
99
52+
112
53+
117
54+
99
55+
111
56+
100
57+
101
58+
--------
59+
CpuCode
60+
--------
61+
62+
*/

0 commit comments

Comments
 (0)