zoukankan      html  css  js  c++  java
  • StringBuffer类

      

    父类:java.lang.Object  
    java.lang.StringBuffer
    1.StringBuffer构造方法

    1>StringBuffer()
      构造一个不带字符的字符缓冲区,其初始容量为16个字符
    2>StringBuffer(CharSequence seq)
      构造一个字符串缓冲区包含与接口CharSequence相同的字符
      接口CharSequence的实现类包括String类/StringBuffer类/StringBuilder类
      因此StringBuffer(String value)是可以的;
    3>StringBuffer(int capacity)
      指定初始容量的字符串缓冲区
    4>StringBuffer(String str)//见2>
    2.StringBuffer特有方法
    1>public StringBuffer append(int x)//(char value)//(boolean value)
      
          1.StringBuffer leo9257 = new StringBuffer("nanjing.");
    
      2.System.out.println(leo9257);//nanjing.
    
      3.leo9257.append("guiyang");
    
      4.System.out.println(leo9257);//nanjing.guiyang
    
      5.leo9257.append(true).append('@').append(2009);
    
      6.System.out.println(leo9257);//nanjing.guiyangtrue@2009
    
    
    2>public StringBuffer insert(int off,String str)

      

     

    1.StringBuffer leo9257 = new StringBuffer("nanjing.");

      
    2.leo9257.insert(6, "guiyang");//nanjinguiyangg.在索引出插入

      3.leo9257.insert(8, "guiyang");//nanjing.guiyang
    3>public StringBuffer delete(int start,int end)

      

        1.StringBuffer leo9257 = new StringBuffer("nanjing.guiyang2009-201*");
      
    2.leo9257.delete(19,leo9257.length());//nanjing.guiyang2009
    4>public StringBuffer reserve()
      1.StringBuffer leo9257 = new StringBuffer("nanjing.guiyang2009-201*");
      
    2.leo9257.reverse();//*102-9002gnayiug.gnijnan
    
    
    

    5>
    public StringBuffer replace(int Start,int end,String str)
      
        1.StringBuffer leo9257 = new StringBuffer("nanjing...guiyang2009");
      
    2.leo9257.replace(7, 9, "pukou");//nanjingpukou.guiyang2009
    
    
    
    6.eg
    /*
     *
     *将一句话的首字母都转为大写
     *leo9257 is the man who stayed in nanjing for nearly nine years. 
     */
    
    public class UpperCaseDeom {
        public static void main(String[] args) {
            String s = "leo9257 is the man who stayed in Nanjing for nearly 9 years.";
            
            StringBuffer ns = new StringBuffer();
            
            String[] words = s.split(" ");
            
            for (int i = 0; i < words.length; i++) {
                String s0 = words[i].substring(0,1).toUpperCase()+words[i].substring(1);
                ns.append(s0+" ");
            }
            System.out.println(ns);
        }
    }
    View Code
    
    
    
     
     
     
     



  • 相关阅读:
    Oracle存储过程格式
    Parallel并行运算实例
    唐让的领航少年
    株洲县阳光三农网
    株洲县招商网
    利用css新属性appearance优化select下拉框
    谈谈我的出差感想
    颜色表及html代码
    jquery中DOM的操作方法
    HTML DOM的nodeName,nodeValue,nodeType介绍
  • 原文地址:https://www.cnblogs.com/leo9257/p/8877729.html
Copyright © 2011-2022 走看看