常用API-String、包装类、System
importjava.io.IOException;importjava.util.Arrays;publicclassfuxi2_string_system_baozhuanglei{publicstaticvoidmain(String[]args){//***********************字符串*************************************************************//Stringnewstr;Stringstr="Iloveyou";newstr=str.trim();//去掉字符串的前后空格newstr=str.toUpperCase();//将字符串转为大写newstr=str.toLowerCase();//将字符串转为小写newstr=str.substring(1);//从某个位置开始截取字符串生成新的字符串newstr=str.substring(5,8);//从某个位置开始到某个位置截取字符串生成新的字符串newstr=String.valueOf(87899);//将其他类型转为字符串newstr=str.concat("fff");//在原有字符串的结尾加上指定字符串生成新的字符串System.out.println(newstr);booleanbs=str.startsWith("i");//判断是否以某个字符串开头bs=str.endsWith(".doc");//判断是否以某个字符串结尾bs=str.contains("h");//判断是否包含某个字符串bs=str.isEmpty();//判断字符串是否为空charc=str.charAt(6);//获取字符串某个位置的字符intp=str.indexOf("co");//获取某个字符(串)在字符串中第一次出现的位置,没有返回-1p=str.lastIndexOf('o');//获取某个字符(串)在字符串中最后一次出现的位置p=str.indexOf('v',3);//从3开始是否包含v,是返回v的位置4,否返回-1p=str.length();//计算字符串长度System.out.println(p);String[]array=str.split("o");//将字符串某个字符分段截取,返回字符串数组System.out.println(Arrays.toString(array));//打印结果:[Il,vey,u]//***********************包装类自动填装箱*************************************************************//booleanf=false;Booleanff=newBoolean(f);//创建包装类booleanfz=Boolean.parseBoolean("TRue");//将字符串转成基本类型fz=ff.booleanValue();//从包装类转成基本类型charch='5';Charactercha=newCharacter(ch);booleanbc=cha.isDigit(ch);//判断字符是否是数字bc=Character.isUpperCase('D');//判断是否为大写charcz=cha.charValue();//从包装类转成基本类型intin=Integer.MAX_VALUE;//获取整型最大值2^31-1in=Integer.parseInt("568512");//将字符串转成基本类型//***********************System常用API*************************************************************//for(inti=0;i<10;i++){System.out.println(i);}System.exit(1);//退出程序,终止java虚拟机。参数为非0整型。Runtimerun=Runtime.getRuntime();//创建runtime对象,通过方法得到try{run.exec("C:/ProgramFiles(x86)/Tencent/QQ/Bin/QQ.exe");//execute执行exe程序}catch(IOExceptione){e.printStackTrace();}//////////////////////////////////////////////////////////////////////System.arraycopy();//高效率复制数组Runtime.getRuntime().exec("D:\\ProgramFiles\\SDKSetup.exe");//启动某个应用}}
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。