氟塑料离心泵www.buybeng.com

jquery教程http://www.software8.co/wzjs/jquery/

StringBuffer的常用方法

  1. //通过append()方法连接各种类型的数据  
  2. /*public class Append{ 
  3.     public static void main(String []args){ 
  4.         StringBuffer buf = new StringBuffer(); 
  5.         buf.append("Hello \n"); 
  6.         buf.append("Hello ").append("World!\n"); 
  7.         buf.append("数字:").append(1).append("\n");//代码链 
  8.         buf.append("布尔:").append(true); 
  9.         System.out.println(buf); 
  10.     } 
  11. }*/  
  12. /*public class Append{ 
  13.     public static void main(String []args){ 
  14.         StringBuffer buf = new StringBuffer(); 
  15.         buf.append("Hello "); 
  16.         fun(buf); 
  17.         System.out.println(buf); 
  18.     } 
  19.     public static void fun(StringBuffer s){ 
  20.         s.append("MLDN ").append("LiXingHua"); 
  21.     } 
  22. }*/  
  23. //Hello MLDN LiXingHua  
  24.   
  25. //直接使用insert()方法在指定位置上为StringBuffer添加内容  
  26. /*public class Append{ 
  27.     public static void main(String []args){ 
  28.         StringBuffer buf = new StringBuffer(); 
  29.         buf.append("Hello!!!"); 
  30.         buf.insert(0,"Hello "); 
  31.         System.out.println(buf); 
  32.         buf.insert(buf.length()," MLDN~~"); 
  33.         System.out.println(buf); 
  34.     } 
  35. }*/  
  36.   
  37. //字符串反转操作--reverse  
  38. /*public class Append{ 
  39.     public static void main(String []args){ 
  40.         StringBuffer buf = new StringBuffer(); 
  41.         buf.append("World!!!"); 
  42.         buf.insert(0,"Hello "); 
  43.         String str = buf.reverse().toString(); 
  44.         System.out.println(str); 
  45.     } 
  46. }*/  
  47.   
  48. //替换指定范围的内容--replace  
  49. /*public class Append{ 
  50.     public static void main(String []args){ 
  51.         StringBuffer buf = new StringBuffer(); 
  52.         buf.append("Hello ").append("World!!"); 
  53.         buf.replace(6,11,"LiXiHua"); 
  54.         System.out.println(buf); 
  55.     } 
  56. }*/  
  57.   
  58. //字符串截取--substring  
  59. /*public class Append{ 
  60.     public static void main(String []args){ 
  61.         StringBuffer buf = new StringBuffer(); 
  62.         buf.append("Hello ").append("World!!"); 
  63.         buf.replace(6,11,"LiXiHua"); 
  64.         String str = buf.substring(6,15); 
  65.         System.out.println(str); 
  66.     } 
  67. }*/  
  68.   
  69. //删除指定范围的字符串--delete  
  70. /*public class Append{ 
  71.     public static void main(String []args){ 
  72.         StringBuffer buf = new StringBuffer(); 
  73.         buf.append("Hello ").append("World!!"); 
  74.         buf.replace(6,11,"LiXiHua"); 
  75.         String str = buf.delete(6,15).toString(); 
  76.         System.out.println(str); 
  77.     } 
  78. }*/  
  79.   
  80. //查找指定的内容是否存在--indexOf  
  81. public class Append{  
  82.     public static void main(String []args){  
  83.         StringBuffer buf = new StringBuffer();  
  84.         buf.append("Hello ").append("World!!");  
  85.         if(buf.indexOf("Hello")==-1){  
  86.             System.out.println("没有找到指定内容");  
  87.         }else{  
  88.             System.out.println("可以找到指定内容");  
  89.         }  
  90.     }  
  91. }  

posted on 2012-10-22 09:56 你爸是李刚 阅读(144) 评论(0)  编辑  收藏


只有注册用户登录后才能发表评论。


网站导航:
 
<2012年10月>
30123456
78910111213
14151617181920
21222324252627
28293031123
45678910

导航

统计

常用链接

留言簿

随笔档案

文章档案

技术网站

行业网站

搜索

最新评论

阅读排行榜

评论排行榜

站长网 氟塑料离心泵 注塑机 液晶广告机