0

How to display address of string elements in java

String - Java

28th Jan 2022, 11:37 AM
Akash Manjre
4 Respuestas
+ 2
String str = "hello"; System.out.println(str.hashCode()) ; but it's not exactly address but a reference. why you need address in java? java dont deal with addresses.. https://stackoverflow.com/questions/18396927/how-to-print-the-address-of-an-object-if-you-have-redefined-tostring-method
28th Jan 2022, 12:32 PM
Jayakrishna 🇮🇳
+ 2
String str1 = "abcd", str2 = "abcd"; System.out.println( System.identityHashCode(str1) ); System.out.println( System.identityHashCode(str2) );
28th Jan 2022, 1:30 PM
zemiak
+ 2
Hashcode is a unique code or an 32bit integer number generated by the JVM at time of object creation in java. https://www.geeksforgeeks.org/method-class-hashcode-method-in-java/ public static int identityHashCode(Object x) Returns the same hash code for the given object as would be returned by the default method hashCode(), whether or not the given object's class overrides hashCode(). The hash code for the null reference is zero. https://docs.oracle.com/javase/8/docs/api/java/lang/reflect/Method.html#hashCode-- https://docs.oracle.com/javase/8/docs/api/java/lang/System.html#identityHashCode-java.lang.Object- public class Program { public static void main(String[] args) { String str1 = "abcd", str2 = "abcd"; System.out.println(System.identityHashCode(str1) ); System.out.println(System.identityHashCode(str2)); System.out.println( str1.hashCode() ); //32bit System.out.println( str2.hashCode() ); } }
28th Jan 2022, 1:46 PM
Jayakrishna 🇮🇳
0
What is hashcode bro. And beause i need this.Thanks bro
28th Jan 2022, 12:41 PM
Akash Manjre