lomeo: (гомер)
Dmitry Antonyuk ([personal profile] lomeo) wrote2006-07-12 11:22 am

java string cache

Только вчера с удивлением обнаружил, что стринговый кэш в java всё таки работает:


public class Test
{
    public static final void main(String[] args)
        throws Exception
    {
        String test1    = "this is a text";
        String subTest1 = test1.substring(10);

        String test2    = "this is not a text";
        String subTest2 = test2.substring(14);

        System.out.println(subTest1 == subTest2);
        System.out.println(subTest1.intern() == subTest2.intern());
    }
}


вернёт

false
true

Post a comment in response:

This account has disabled anonymous posting.
If you don't have an account you can create one now.
HTML doesn't work in the subject.
More info about formatting