InterviewSolution
| 1. |
Public Class A { Public Static Void Main(string Args[]){ Final String S1="job"; Final String S2="seeker"; String S3=s1.concat(s2); String S4="jobseeker"; System.out.println(s3==s4); // Output 1 System.out.println(s3.hashcode()==s4.hashcode()); Output 2 } } What Will Be The Output 1 And Output 2 ? |
|
Answer» S3 and S4 are pointing to different memory location and hence Output 1 will be FALSE. Hash CODE is generated to be used as hash KEY in some of the collections in Java and is calculated USING string characters and its length. As they both are same string literals, and hence their hashcode is same.Output 2 will be true. S3 and S4 are pointing to different memory location and hence Output 1 will be false. Hash code is generated to be used as hash key in some of the collections in Java and is calculated using string characters and its length. As they both are same string literals, and hence their hashcode is same.Output 2 will be true. |
|