String

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package week03;
 
import java.util.Scanner;
 
public class TestString {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
 
        String a = sc.nextLine();
 
        //字符串变字符数组
        /*char[] chars = a.toCharArray();
        for(int i = 0; i < a.length(); i++)
        {
            System.out.print(chars[i]);
        }*/
 
        //字符数组变字符串
        /*char[] chars = a.toCharArray();
        String s = new String(chars);
        System.out.println(s);*/
 
        //截取子串
        /*String substring = a.substring(1, 3);
        System.out.println(substring);*/
 
        //查看是否是子串
        /*boolean ab = a.contains("ab");
        System.out.println(ab);*/
 
        //链接字符串,更多的用+
        /*String concat = a.concat(a);
        System.out.println(concat);*/
 
        //串与stringbuffer比较
        /*StringBuffer c = new StringBuffer("aba");
        boolean b = a.contentEquals(c);
        System.out.println(b);*/
 
        //返回哈希值
        /*int hash = a.hashCode();
        System.out.println(hash);*/
 
        //找值
        /*int i = a.indexOf('c');
        System.out.println(i);
        int ab = a.indexOf("ab");
        System.out.println(ab);*/
 
        //不用草
        /*int aba = a.compareTo("aaa");
        System.out.println(aba);*/
    }
}

  

posted @   爽爽子的秃头生活  阅读(4)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
点击右上角即可分享
微信分享提示