Click to See Complete Forum and Search --> : .intern() ?
Jareware
Nov 12th, 2001, 09:56 AM
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-
Dillinger4
Nov 12th, 2001, 10:05 AM
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.
Jareware
Nov 12th, 2001, 10:08 AM
:o Ahem, I'm pretty new to java... What would that be in english? :D
-JR-
Jareware
Nov 12th, 2001, 10:10 AM
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-
Dillinger4
Nov 12th, 2001, 10:13 AM
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.
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
}
Jareware
Nov 12th, 2001, 10:15 AM
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-
Dillinger4
Nov 12th, 2001, 10:17 AM
That i have no clue. My documentation doesn't say. :(
Jareware
Nov 12th, 2001, 10:19 AM
I see... Have you tried using it?
-JR-
Dillinger4
Nov 12th, 2001, 10:32 AM
Nope. Never had a need too. :p
Jareware
Nov 12th, 2001, 12:11 PM
Well, me neither, I just need to know what it does :)
-JR-
crptcblade
Nov 12th, 2001, 03:14 PM
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.
:)
Jareware
Nov 13th, 2001, 07:01 AM
K, thanks, I'll try and figure out what you meant... :D
-JR-
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.