zoukankan      html  css  js  c++  java
  • java学习日记 StringBuffer类

    1、与String区别1

    String用+连接字符

    StringBuffer用append()方法

    String不能修改

    StringBuffer可修改

    public class StringBufferDemo1 {
        public static void main(String[] args) {
            StringBuffer sbu = new StringBuffer();
            sbu.append("Hello").append("World").append("!!!");
            System.out.println("修改之前:"+sbu);
            System.out.println("修改之后:"+change(sbu));
    
        }
        public static StringBuffer change(StringBuffer temp){
            return temp.append("jxqwc").append("gaile");
        }
    }

    运行结果:

    修改之前:HelloWorld!!!
    修改之后:HelloWorld!!!jxqwcgaile

    2、两种方法将String类转换成StringBuffer类

    public class StringBufferDemo1 {
        public static void main(String[] args) {
            StringBuffer sbu = new StringBuffer("Hello");
            System.out.println(sbu);
           }
    }
    public class StringBufferDemo1 {
        public static void main(String[] args) {
            StringBuffer sbu = new StringBuffer();
            sbu.append("Hello");
            System.out.println(sbu);
        }
    }

    3、将StringBuffer类转换成String类

    public class StringBufferDemo1 {
        public static void main(String[] args) {
            StringBuffer sbu = new StringBuffer("Hello");
            String str = sbu.toString();
            System.out.println(sbu);
        }
    }

  • 相关阅读:
    HelpersRainCaptcha
    HelpersPHPMailer
    HelpersPassword
    HelpersPagination
    HelpersNumber
    HelpersHooks
    HelpersGeoCode
    HelpersFastCache
    HelpersDocument
    eclipse 设置jsp页面为HTML5
  • 原文地址:https://www.cnblogs.com/cathycheng/p/13204267.html
Copyright © 2011-2022 走看看