java 字符串获取

package java07;
/*
String 当中与获取相关的常用方法

public int length();  获取字符串当中含有的字符的个数,得到字符串的长度
public String concat(String str);  将当前字符串和参数字符串拼接成为新的字符串返回
public char charAt(int index);  获取指定索引位置的单个字符
public int intdexOf(String str) ; 查找参数字符串在本字符串当中出现的索引位置,如果没有就返回-1

* */

public class DemoStringget {
    public static void main(String[] args) {
        //获取字符串长度
        int length = "hsghkshgiu2gjkhg2".length();
        System.out.println(length);//17

        //拼接字符串
        String str1 = "Hello";
        String str2 = "World!";
        String str3 = str1.concat(str2);//
        System.out.println(str3);//HelloWorld!

        //获取指定索引位置的单个字符
        char ch1 = str1.charAt(4);
        char ch2 = str1.charAt(0);
        System.out.println(ch1);//o
        System.out.println(ch2);//H

        //查找参数字符串在本来字符串汇总出现的第一次索引位置
        String str4 = "Wo";
        int index = str3.indexOf(str4);
        System.out.println(index);//5

    }
}