package test1;
/*
* String当中与获取相关的常用方法有:
* public int length(),获取字符串当中含有的字符个数,拿到字符长度;
* public String concat(String str),将当前字符串和参数字符串拼接成为返回值新的字符串。
* public char charAt(int index),获取指定索引位置的单个字符(索引从0开始)
* public int indexof(String str),查找餐宿字符串在本字符串当中首次出现的索引值,如果没有返回-1值
*
* */
public class test1{
public static void main(String[] args) {
int length="adsfasfasdfadsf".length();
System.out.println(length);
// 拼接字符串
String str1="Hallo";
String str2="World";
System.out.println(str1.concat(str2));
System.out.println("***********************");
//获取指定索引位置的单个字符
char ch="hallo".charAt(2);
System.out.println(ch);
System.out.println("***********************");
// 查找参数字符串在本来字符串当中出现的第一次索引位置;
// 如果根本 没有返回值则返回-1
String origin="halloworldhalloworld";
int n=origin.indexOf('e');
System.out.println(n);//1

}
}

字符串截取方法
String c = "abc".substring(2,3);
     String d = cde.substring(1, 2);
字符串转换方法

 

char[] toCharArray()
          将此字符串转换为一个新的字符数组。

转换为字节数组
public byte【】getByte();
转化为ASCII值

public String replace(charSquence oldString,charSquency newString);


package test1;

import java.lang.CharSequence;

public class test1{
public static void main(String[] args){
String str="happy";
String str1="happy2";

byte[]num=str.getBytes();
System.out.println(str);
for (int i=0;i<num.length-1;i++)
{
System.out.println(num[i]);
}
// charsquence 可以接受字符串类型
String a=str.replace( "a","mmmm");
System.out.println(a); //字符串的字符变换
}
}

字符串分割方法
public String【】 split(String regex),按照参数的规则,将字符串划分为若干个部分
regex 可以是: : , 。