Click here to watch in Youtube :
https://www.youtube.com/watch?v=BhehDFtT6NQ&list=UUhwKlOVR041tngjerWxVccw
HashCodeTest.java
Output
https://www.youtube.com/watch?v=BhehDFtT6NQ&list=UUhwKlOVR041tngjerWxVccw
HashCodeTest.java
public class HashCodeTest { public static void main(String[] args) { System.out.println("Hashcode test of String:"); /* * String is immutable(once created, can not be * modified). */ String str = "Welcome"; System.out.println("Before Concat,HashCode = " + str.hashCode()); str = str + "Peter"; System.out.println("After Concat,HashCode = " + str.hashCode()); System.out.println("---------------------------------"); System.out.println("Hashcode test of StringBuilder:"); /* * StringBuilder is mutable (once created, can be * modified. */ StringBuilder sb = new StringBuilder("Welcome"); System.out.println("Before Concat,HashCode = " + sb.hashCode()); sb.append("Peter"); System.out.println("After Concat,HashCode = " + sb.hashCode()); } }
Hashcode test of String: Before Concat,HashCode = -1397214398 After Concat,HashCode = 44468202 --------------------------------- Hashcode test of StringBuilder: Before Concat,HashCode = 2114664380 After Concat,HashCode = 2114664380
https://sites.google.com/site/javaee4321/java/StringBuilderDemo_Hashcode_diff_App.zip?attredirects=0&d=1
Github Link:
https://github.com/ramram43210/Java/tree/master/BasicJava/StringBuilderDemo_Hashcode_diff_App
Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/c539eeaf4c6ff331d8e2aa2333826ea70c999093/BasicJava/StringBuilderDemo_Hashcode_diff_App/?at=master
See also:
No comments:
Post a Comment