Warning: include_once(): http:// wrapper is disabled in the server configuration by allow_url_include=0 in /home/users/2/moriya-h5/web/confrage/java/string/string/string.html on line 2

Warning: include_once(http://www.confrage.com/bin/header.php): failed to open stream: no suitable wrapper could be found in /home/users/2/moriya-h5/web/confrage/java/string/string/string.html on line 2

Warning: include_once(): Failed opening 'http://www.confrage.com/bin/header.php' for inclusion (include_path='.:/usr/local/php/5.6/lib/php') in /home/users/2/moriya-h5/web/confrage/java/string/string/string.html on line 2
String型の省メモリプログラミング | Java | 株式会社CONFRAGE
Warning: include_once(/home/sites/heteml/users/m/o/r/moriya-h5/web/confrage/bin/menu.php): failed to open stream: No such file or directory in /home/users/2/moriya-h5/web/confrage/java/string/string/string.html on line 17

Warning: include_once(): Failed opening '/home/sites/heteml/users/m/o/r/moriya-h5/web/confrage/bin/menu.php' for inclusion (include_path='.:/usr/local/php/5.6/lib/php') in /home/users/2/moriya-h5/web/confrage/java/string/string/string.html on line 17
String型の省メモリプログラミング
String型はnew String()しているコードをよく見ます。
省メモリプログラミングを考えるならば、インスタンス化するのではなく、String str = ""とすべきです。

以下、サンプルです。

package purejava;

public class Sample {

    public static void main(String[] args) {
        String value1 = "a";
        String value2 = "a";
        String value3 = new String("a");
        String value4 = new String("a");
        System.out.println(value1 == value2);
        System.out.println(value1 == value3);
        System.out.println(value3 == value4);
    }
}
実行結果は以下になります。

true
false
false
false
参照型の==比較はメモリ番地を比較しています。上記の結果をみると、value3とvalue4は同じ文字列であるにもかかわらず異なるメモリ番地を使用しているのがわかります。
逆にvalue1とvalue2は同じ番地を参照しているのがわかります。

Back to top

Information

Warning: include_once(/home/sites/heteml/users/m/o/r/moriya-h5/web/confrage/bin/side_bar.php): failed to open stream: No such file or directory in /home/users/2/moriya-h5/web/confrage/java/string/string/string.html on line 82

Warning: include_once(): Failed opening '/home/sites/heteml/users/m/o/r/moriya-h5/web/confrage/bin/side_bar.php' for inclusion (include_path='.:/usr/local/php/5.6/lib/php') in /home/users/2/moriya-h5/web/confrage/java/string/string/string.html on line 82

Warning: include_once(/home/sites/heteml/users/m/o/r/moriya-h5/web/confrage/bin/seo.php): failed to open stream: No such file or directory in /home/users/2/moriya-h5/web/confrage/java/string/string/string.html on line 91

Warning: include_once(): Failed opening '/home/sites/heteml/users/m/o/r/moriya-h5/web/confrage/bin/seo.php' for inclusion (include_path='.:/usr/local/php/5.6/lib/php') in /home/users/2/moriya-h5/web/confrage/java/string/string/string.html on line 91