首页 > 其他 > 详细

StringBuffer&Runtime demo

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

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

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!