温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

常用API-String、包装类、System

发布时间:2020-07-08 21:27:16 来源:网络 阅读:262 作者:glblong 栏目:开发技术

 

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

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI