Quick actions

cmd+k|ctrl+k

Navigation

Languages

String pool sample

Snippet info

Language

Java

Visibility

public

Author

memo.minsk

Created

2015-09-23T11:58:41Z

Updated

2015-09-23T11:58:41Z

public class Main {
    public static void main(String[] args) {

        String s = "hello";
        final String lo = "lo";

        String[] arr1 = {
                "hello",
                "hel" + "lo",
                "hel" + lo,
                new String("hello").intern()
        };

        String[] arr2 = {
                new String("hello"),
                "hel".concat("lo"),
                " hello ".trim(),
                new StringBuilder("hello").toString()
        };

        System.out.println("arr1:");
        for (int i = 0; i < arr1.length; i++) {
            System.out.print((s == arr1[i]) + " ");
        }

        System.out.println("\narr2:");
        for (int i = 0; i < arr2.length; i++) {
            System.out.print((s == arr2[i]) + " ");
        }

    }
}
INFO