码迷,mamicode.com
首页 > 其他好文 > 详细

StringBuffer&Runtime demo

时间:2014-08-12 12:47:54      阅读:183      评论:0      收藏:0      [点我收藏+]

标签:style   color   io   strong   for   ar   cti   amp   

public class StringBufferDemo02 {
    public static void main(String[] args) {
        StringBuffer bf = new StringBuffer("I am bf,");
        // bf="I am a bf,";
        fun1(bf);
        String str = "I am str,";
        fun2(str);
        String str1 = fun3(str);
        System.out.println(bf);
        System.out.println(str);
        System.out.println(str1);
    }

    public static void fun1(StringBuffer sb) {
        sb.append(" has changed!");
    }

    public static void fun2(String str) {
        str += " HAS CHANGED!";
    }

    public static String fun3(String str) {
        str += " has changeeeeeeed!";
        return str;
    }
}

Output:

I am bf, has changed!
I am str,
I am str, has changeeeeeeed!

 

 

public class RunTimeDemo {
    public static void main(String[] args) {
        Runtime runtime = Runtime.getRuntime();
        System.out.println("JVM‘S MAX MEMORY:" + runtime.maxMemory());
        System.out.println("JVM‘S FREE MEMORY:" + runtime.freeMemory());
        String string = "Hello" + "wORLD" + "!!!" + "\t" + "wellcomde" + "tO"
                + "VON" + "~~";
        System.out.println(string);
        for (int x = 0; x < 1000; x++) {
            string += x;
        }
        System.out.println("After String‘s operate,JVM‘S FREE MEMORY:"
                + runtime.freeMemory());
        runtime.gc();
        System.out.println("After Garbage collection,JVM‘S FREE MEMORY:"
                + runtime.freeMemory());
    }
}

StringBuffer&Runtime demo,布布扣,bubuko.com

StringBuffer&Runtime demo

标签:style   color   io   strong   for   ar   cti   amp   

原文地址:http://www.cnblogs.com/vonk/p/3906772.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!