/*
String类中的创建方法 String s = new String("good");
1.char a = {'g','o','o','d'};
String s = new String (a,2,2);==>od
2.char a = {'g','o','o','d'};
String s = new String(a);
3.String s;
s = "good";

*/
public class StringDemo {
public static void main(String[] args)
{
char [] a= {'时','间'};
String s = new String(a,0,2);
System.out.println(s);

char [] a1= {'就','是'};
String s1 = new String (a1);
System.out.print(s1);

String s2,s3;
s2 = "We ";
s3 = "are";
System.out.println(s2+s3);

}

}

 

 

/*
String 类型的查询位置
String 类中提供4种来查询的方法:
public int indexOf(String str);//如果查询到就是字符第一个出现的位置s.[角标]的角标,没查询到就返回-1
public int lastIndexOf(String str);//查询的是字符最后一次出现的位置字符串的角标,没查询到就返回-1
public int indexOf(String str,int fromindex)指定位置往后查
public int lastIndexOf(String str,int fromindex)从指定位置往前查询

例子:
在 两个字符串中8888和B888查询出不同
*/
public class StringSearchDemo {
public static void main(String[] args) {
String s = new String("we are friend !");
int x = s.indexOf("e");//s【3】首次出现的位置
System.out.println(x);
int q = s.lastIndexOf("e");//s[10];最后一次的位置
System.out.println(q);

String s1 = "8888";
String s2 = "B888";

if (s1.indexOf("B")>-1)
{
System.out.println(s1+"这个字符串包含B");
}
if (s2.indexOf("B")>-1)
{
System.out.println(s2+"这个字符串包含B");
}

}

}


/*
String 类中长度的查询
用s.length()的方法来查询长度然后赋值给一个局部变量
注意其中空格也占一个长度
*/

public class StringDemo2 {
public static void main(String[] args) {
String s1 = new String ("hello");
String s2 = new String ("world");
String s3 = s1+" " +s2;
System.out.println(s3);
int size1 = s1.length();
System.out.println(size1);
int size2= s2.length();
System.out.println(size2);
int size3 = s3.length();
System.out.println(size3);
}

}