• StringBuffer&Runtime demo


    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" + "!!!" + " " + "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());
        }
    }

  • 相关阅读:
    函数的参数设置
    定义函数
    使用dict和set
    (转)set集合的应用
    循环与range
    if语句
    How to use git hub
    Install pyodbc in OpenSUSE
    Ubuntu编译安装PHP7
    Ubuntu为已经安装的PHP7单独编译mysqli
  • 原文地址:https://www.cnblogs.com/vonk/p/3906772.html
Copyright © 2020-2023  润新知