Facebook

adsense

Monday 18 May 2015

QUESTION 18

What is the difference between creating String as new() and literal?
Solution :
When we create string with new() Operator, it’s created in heap and not added into string pool while String created using literal are created in String pool itself which exists in PermGen area of heap.

String s = new String("Test");

does not  put the object in String pool , we need to call String.intern() method which is used to put  them into String pool explicitly. its only when you create String object as String literal e.g. String s = "Test" Java automatically put that into String pool.

            <PREVIOUS || Main Page || NEXT >
              GIVE YOUR COMMENT BELOW

1 comment:

  1. Interesting Article. Hoping that you will continue posting an article having a useful information. Patient Accounting Software

    ReplyDelete