📄 strconstruct.java
字号:
class StrConstruct{
public static void main(String[] args){
String s1=new String();
System.out.println("s1=\""+s1+"\"");
String s2=new String("Hello World");
System.out.println("s2=\""+s2+"\"");
char[] cArray={'a','b','c','z','y','x'};
String s3=new String(cArray);
System.out.println("s3=\""+s3+"\"");
String s4=new String(cArray,0,3);
System.out.println("s4=\""+s4+"\"");
byte[] b={51,52,53,54,55};
String s5=new String(b);
System.out.println("s5=\""+s5+"\"");
StringBuffer buffer=new StringBuffer("edit string");
String s6=new String(buffer);
System.out.println("s6=\""+s6+"\"");
byte[] b2=new byte[5];
String s=new String("mnopq");
b2=s.getBytes();
for(int i=0;i<5;i++)
System.out.println("b2["+i+"]="+b2[i]);
String s22=new String("abcdefghijklmn");
char[] tArray=new char[5];
s22.getChars(3,5,tArray,2);
for(int i=0;i<5;i++)
System.out.println("tArray["+i+"]="+tArray[i]);
String sdd=new String("But it had all worked out for the best.");
String g=sdd.substring(26);
System.out.println(g);
String sff=new String("hello,世事洞明皆学问,人情练达即文章");
String g1=sff.substring(6,13);
System.out.println(g1);
String s1e=new String("abcd");
String s2e=new String("abcde");
System.out.println("字符串s1与s2的比较:"+s1e.compareTo(s2e));
String s1kk=new String("Mr Corleone's voice came briskly over the phone.");
System.out.println(s1kk.endsWith("the phone."));
System.out.println(s1kk);
String s1aa=new String("xyzABC");
String s2aa=new String("XYZabc");
System.out.println(s1aa.equalsIgnoreCase(s2aa)+"ddd");
String s1000=new String("yzj12345");
char[] cArray11={'y','z','j','1','2','3','4','5'};
String s2000=new String(cArray11);
System.out.println("s1000与cArray相等否:"+s1.equals(cArray11));
System.out.println("s1000与s2000相等否:"+s1000.equals(s2000));
String s1007=new String("mnopXWYZbefgh");
String s2007=new String("123XWYZ456");
System.out.println(s1007.regionMatches(4,s2007,3,4));
String sttt=new String("0123456789");
System.out.println(sttt.indexOf('a'));
String svv=new String("Why don't we go into my study?");
System.out.println(svv.indexOf('o',7));
String sbb=new String("Why don't we go into my study?");
System.out.println(sbb.indexOf("we"));
String sggg=new String("a123a123");
System.out.println(sggg.lastIndexOf('a'));
String s343=new String("this is a String");
System.out.println("字符串s的长度为:"+s343.length());
String s76=new String("Good");
String u=new String("night!");
System.out.println(s76.concat(u));
String s99=new String("那只0生了一个0子");
System.out.println(s99.replace('0', '鸭'));
String s90=new String("AbcdeEfG");
System.out.println(s90.toLowerCase());
String s221=new String("abcedfghijk");
System.out.println(s221.toUpperCase());
String sf55=new String(" mykey is 12345 ");
System.out.println(sf55.trim());
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -