This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes How to get address of String object? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How to get address of String object?" Watch "How to get address of String object?" New topic

How to get address of String object?

Sam Drake
Ranch Hand

Joined: Jun 05, 2003
Posts: 33
Say I have the following statement:
String s1 = "abc";
How can I get the address of the memory for the variable s1?
I'm a beginner with a C background.
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24168

You can't, at least not in the Java language (or in any code running on the JVM itself.) Java's pointers aren't addresses. The concept of pointer/address equivalence is not part of the JVM architecture.
In C/C++ code using the Java Native Interface (JNI), which Java code can call out to, you can get a more or less opaque handle to the JVM's data structure representing that String object, but it's not really "a pointer to the String", either.

[Jess in Action][AskingGoodQuestions]
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
subject: How to get address of String object?
Similar Threads
Garbage Collection
How many Objects are garbage collected?
Immutability of strings???
Java String pool problem