What does .intern() do when handling strings? For example, if I have a string variable called myString and I do the following:
someOtherVariable = myString.intern();
What does it store in the other one?
-JR-
Printable View
What does .intern() do when handling strings? For example, if I have a string variable called myString and I do the following:
someOtherVariable = myString.intern();
What does it store in the other one?
-JR-
The signature of the method is public String intern(); so i assume that it returns a String but i noticed also that it is declared native.
:o Ahem, I'm pretty new to java... What would that be in english? :D
-JR-
Oh, I'm sorry, if I presented the problem the wrong way:
What does it do to the string? (i.e. Trim() takes off preceeding and following spaces)
-JR-
You can do somthing like this to run a native method, which is a method from another language. Since Java can only run C++ i guess that it is a C++ method, im not too sure though.
Code:public class Native{
/* the static initializer ensures that the native library
will be loaded before the methood is called
*/
static{
System.loadLibrary(NativeLibrarylib);
}
public void nativeMethod(); //native method protype
}
Quote:
Originally posted by Jareware
Oh, I'm sorry, if I presented the problem the wrong way:
What does it do to the string? (i.e. Trim() takes off preceeding and following spaces)
-JR-
That i have no clue. My documentation doesn't say. :(
I see... Have you tried using it?
-JR-
Nope. Never had a need too. :p
Well, me neither, I just need to know what it does :)
-JR-
:)Quote:
public String intern()Returns a canonical representation for the string object.
A pool of strings, initially empty, is maintained privately by the class String.
When the intern method is invoked, if the pool already contains a string equal to this String object as determined by the equals(Object) method, then the string from the pool is returned. Otherwise, this String object is added to the pool and a reference to this String object is returned.
It follows that for any two strings s and t, s.intern() == t.intern() is true if and only if s.equals(t) is true.
All literal strings and string-valued constant expressions are interned. String literals are defined in ยง3.10.5 of the Java Language Specification
Returns:
a string that has the same contents as this string, but is guaranteed to be from a pool of unique strings.
K, thanks, I'll try and figure out what you meant... :D
-JR-