I've written the following code for the test I want reason for the difference between == and .equals. a why == is giving true for the "Test1"
(Changed title to be meaningful) [ June 06, 2007: Message edited by: Barry Gaunt ]
posted 8 years ago
This sort of question has been discussed hundreds of times. If you use the search facility of JavaRanch, you will find so many interesting discussion on this.
Hint: When you use new operator to create String object, object is created at run time. Without using "new" you call compile time created String object. Objects created with "new", gives false result when you use == to compare them even if the content is same. Because == compares references of the objects.