您的位置:首页 > 其它

常用API-String、包装类、System

2013-04-25 23:18 274 查看
[code]import java.io.IOException;import java.util.Arrays;public class fuxi2_string_system_baozhuanglei{public static void main(String[] args){//***********************字符串*************************************************************//String newstr;String str = " 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);boolean bs = str.startsWith("i");//判断是否以某个字符串开头bs = str.endsWith(".doc"); //判断是否以某个字符串结尾bs = str.contains("h");//判断是否包含某个字符串bs = str.isEmpty();//判断字符串是否为空char c = str.charAt(6);//获取字符串某个位置的字符int p = 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]//***********************包装类   自动填装箱*************************************************************//boolean f = false;Boolean ff = new Boolean(f);//创建包装类boolean fz = Boolean.parseBoolean("TRue");//将字符串转成基本类型fz = ff.booleanValue();//从包装类转成基本类型char ch = '5';Character cha = new Character(ch);boolean bc = cha.isDigit(ch);//判断字符是否是数字bc = Character.isUpperCase('D');// 判断是否为大写char cz = cha.charValue();//从包装类转成基本类型int in = Integer.MAX_VALUE;//获取整型最大值  2^31 - 1in = Integer.parseInt("568512");//将字符串转成基本类型//***********************System常用API*************************************************************//for (int i = 0; i < 10; i++){System.out.println(i);}System.exit(1);// 退出程序,终止java虚拟机。参数为非0整型。Runtime run = Runtime.getRuntime();//创建runtime对象,通过方法得到try{run.exec("C:/Program Files (x86)/Tencent/QQ/Bin/QQ.exe");// execute   执行exe程序}catch (IOException e){e.printStackTrace();}//////////////////////////////////////////////////////////////////////System.arraycopy();  //高效率复制数组Runtime.getRuntime().exec("D:\\Program Files\\SDK Setup.exe");//启动某个应用}}
[/code]
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  String