Yeah, nothing's wrong.
One more thing I wana talk about string is that if you want to handle
a really big file with many different string at a time. Do not use
String class, use StringBuilder or StringBuffer instead. As Anuj Kumar
have said, the jvm do not delete the string after no variable
references to that string any more. After some time, the memory of
heap space will lack and can not create other String:)
On Sep 22, 4:22 am, ANUJ KUMAR <kumar.anuj...@gmail.com> wrote:
> class test
> {
>
> public static void main(String args[])
> {
>  String x1 = "abc";
> String x2 = "ab";
> x2 = x2 + "c";
>   System.out.println(x1==x2);
>
> }
> }
>
> why does it print false?
>
> in this case 3 objects will be formed in the string pool and they will be
> ("abc"),("ab").("c")and both the refrences x1,x2 will point to ("abc")
> i concluded this from ->
> To make Java more memory efficient,
> the JVM sets aside a special area of memory called the “String constant
> pool.” When
> the compiler encounters a String literal, it checks the pool to see if an
> identical String
> already exists. If a match is found, the reference to the new literal is
> directed to the
> existing String, and no new String literal object is created.
> Please tell me whats the flaw in what i am thinking
> Thanks&Regards

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Java EE (J2EE) Programming with Passion!" group.
To post to this group, send email to
java-ee-j2ee-programming-with-passion@googlegroups.com
To unsubscribe from this group, send email to
java-ee-j2ee-programming-with-passion+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/java-ee-j2ee-programming-with-passion?hl=en?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to