联系客服:400-805-1963

常用API-String、包装类、System
更新:HHH   时间:2023-1-7



 

  1. import java.io.IOException; 
  2. import java.util.Arrays; 
  3.  
  4. public class fuxi2_string_system_baozhuanglei 
  5. { 
  6.     public static void main(String[] args) 
  7.     { 
  8.          
  9.         //***********************字符串*************************************************************// 
  10.         String newstr; 
  11.         String str = " Iloveyou"; 
  12.         newstr = str.trim();//去掉字符串的前后空格 
  13.         newstr = str.toUpperCase();//将字符串转为大写 
  14.         newstr = str.toLowerCase();//将字符串转为小写 
  15.         newstr = str.substring(1);//从某个位置开始截取字符串生成新的字符串 
  16.         newstr = str.substring(5,8);//从某个位置开始到某个位置截取字符串生成新的字符串 
  17.         newstr = String.valueOf(87899);//将其他类型转为字符串 
  18.         newstr = str.concat("fff");//在原有字符串的结尾加上指定字符串生成新的字符串 
  19.         System.out.println(newstr); 
  20.          
  21.         boolean bs = str.startsWith("i");//判断是否以某个字符串开头 
  22.         bs = str.endsWith(".doc"); //判断是否以某个字符串结尾 
  23.         bs = str.contains("h");//判断是否包含某个字符串 
  24.         bs = str.isEmpty();//判断字符串是否为空 
  25.         char c = str.charAt(6);//获取字符串某个位置的字符 
  26.         int p = str.indexOf("co");//获取某个字符(串)在字符串中第一次出现的位置,没有返回-1 
  27.         p = str.lastIndexOf('o');//获取某个字符(串)在字符串中最后一次出现的位置 
  28.         p = str.indexOf('v', 3);//从3开始是否包含v,是返回v的位置4,否返回-1 
  29.         p = str.length();//计算字符串长度 
  30.          
  31.         System.out.println(p); 
  32.          
  33.         String[] array = str.split("o");//将字符串某个字符分段截取,返回字符串数组 
  34.         System.out.println(Arrays.toString(array));//打印结果 :[ Il, vey, u] 
  35.          
  36.          
  37.       //***********************包装类   自动填装箱*************************************************************// 
  38.         boolean f = false; 
  39.         Boolean ff = new Boolean(f);//创建包装类 
  40.         boolean fz = Boolean.parseBoolean("TRue");//将字符串转成基本类型 
  41.         fz = ff.booleanValue();//从包装类转成基本类型 
  42.          
  43.         char ch = '5'; 
  44.         Character cha = new Character(ch); 
  45.         boolean bc = cha.isDigit(ch);//判断字符是否是数字 
  46.         bc = Character.isUpperCase('D');// 判断是否为大写 
  47.         char cz = cha.charValue();//从包装类转成基本类型 
  48.          
  49.         int in = Integer.MAX_VALUE;//获取整型最大值  2^31 - 1 
  50.         in = Integer.parseInt("568512");//将字符串转成基本类型 
  51.          
  52.       //***********************System常用API*************************************************************// 
  53.         for (int i = 0; i < 10; i++) 
  54.         { 
  55.             System.out.println(i); 
  56.         } 
  57.         System.exit(1);// 退出程序,终止java虚拟机。参数为非0整型。 
  58.          
  59.          
  60.         Runtime run = Runtime.getRuntime();//创建runtime对象,通过方法得到 
  61.         try 
  62.         { 
  63.             run.exec("C:/Program Files (x86)/Tencent/QQ/Bin/QQ.exe");// execute   执行exe程序 
  64.         } 
  65.         catch (IOException e) 
  66.         { 
  67.             e.printStackTrace(); 
  68.         }  
  69.         ////////////////////////////////////////////////////////////////////// 
  70.         System.arraycopy();  //高效率复制数组  
  71.  
  72.         Runtime.getRuntime().exec("D:\\Program Files\\SDK Setup.exe");//启动某个应用 
  73.          
  74.          
  75.     } 
  76. } 
返回开发技术教程...