There is so much misconception in your post, it is hard even to start explaining. Get some decent book. For now, some facts that might help you:
- String is not a primitive type,
- there are no pools of primitive types, because there cannot be a reference to a primitive type (the answer saying that they are only kept on the stack is plain wrong!)
- if you use
new
, you bypass pools anyway; so executingnew String("ala")
will always create a new String object; you cannot change the semantics ofnew
; - if you want to use available pools, use factory methods on objects (like
Integer.valueOf
), they will - to some extent - pool instances (it is not viable or beneficial to pool all possible values ofIntegers
,Floats
etc.).