Results 1 to 12 of 12

Thread: .intern() ?

  1. #1

    Thread Starter
    Hyperactive Member Jareware's Avatar
    Join Date
    Nov 2000
    Location
    Silicon Valley, CA
    Posts
    275

    .intern() ?

    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-
    "Blessed are we who can laugh at ourselves for we shall never cease to be amused"
    - Unknown

  2. #2
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418
    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.

  3. #3

    Thread Starter
    Hyperactive Member Jareware's Avatar
    Join Date
    Nov 2000
    Location
    Silicon Valley, CA
    Posts
    275
    Ahem, I'm pretty new to java... What would that be in english?


    -JR-
    "Blessed are we who can laugh at ourselves for we shall never cease to be amused"
    - Unknown

  4. #4

    Thread Starter
    Hyperactive Member Jareware's Avatar
    Join Date
    Nov 2000
    Location
    Silicon Valley, CA
    Posts
    275
    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-
    "Blessed are we who can laugh at ourselves for we shall never cease to be amused"
    - Unknown

  5. #5
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418
    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
      }

  6. #6

    Thread Starter
    Hyperactive Member Jareware's Avatar
    Join Date
    Nov 2000
    Location
    Silicon Valley, CA
    Posts
    275
    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-
    "Blessed are we who can laugh at ourselves for we shall never cease to be amused"
    - Unknown

  7. #7

  8. #8

    Thread Starter
    Hyperactive Member Jareware's Avatar
    Join Date
    Nov 2000
    Location
    Silicon Valley, CA
    Posts
    275
    I see... Have you tried using it?


    -JR-
    "Blessed are we who can laugh at ourselves for we shall never cease to be amused"
    - Unknown

  9. #9

  10. #10

    Thread Starter
    Hyperactive Member Jareware's Avatar
    Join Date
    Nov 2000
    Location
    Silicon Valley, CA
    Posts
    275
    Well, me neither, I just need to know what it does


    -JR-
    "Blessed are we who can laugh at ourselves for we shall never cease to be amused"
    - Unknown

  11. #11
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    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.
    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  12. #12

    Thread Starter
    Hyperactive Member Jareware's Avatar
    Join Date
    Nov 2000
    Location
    Silicon Valley, CA
    Posts
    275
    K, thanks, I'll try and figure out what you meant...


    -JR-
    "Blessed are we who can laugh at ourselves for we shall never cease to be amused"
    - Unknown

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width