Hence in case of intern (first the string is searched for the corresponding string in the pool of string.. if the match is found then the corresponding reference is given to the object.. otherwise new object is created.. if i dont write intern there...
then it wont search in the pool. and will create a new object..
thats the wastage of memory.
if you write String s="testing" // then it will automatically call intern method (implicit call)
but not in the case of String s=new String("testing"); // you have to explicitly provide the intern method
Hence in case of intern (first the string is searched for the corresponding string in the pool of string.. if the match is found then the corresponding reference is given to the object.. otherwise new object is created.. if i dont write intern there...
then it wont search in the pool. and will create a new object..
thats the wastage of memory.
if you write String s="testing" // then it will automatically call intern method (implicit call)
but not in the case of String s=new String("testing"); // you have to explicitly provide the intern method
Where have you read about the equals() method? You ought to look in the API documentation, in Bloch's Effective Java™ (you may be able to find a "sample chapter" from the 1st edition on the internet, which describes equals()), or Google for Angelika Langer Java equals hashCode. There is a lot of useful information there.