un petit article mais qui en dit long sur votre question
http://www.javaworld.com/javaworld/jw-10-2002/jw-1004-java101_p.html
A+ marc

Yannick Emeriaud wrote:
Zeljko VELAJA a écrit :Je m'interroge sur ce que signifie :

  
            prefix = prefix.intern();
            uri = uri.intern();

Qu'est-ce que ça aurait changé si ces deux lignes avaient été omises ?
    

Extrait de la doc de 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."
----------------------------------------------------------------------------------

L'intérêt est donc d'avoir une unicité sur l'élément.

Qu'est-ce que ça aurait changé si ces deux lignes avaient été omises ?
Des doublons dans le Vector declarations.

J'avoue que je ne connaissais pas cette méthode et fonctionnement de
"String".
C'était donc une EXCELLENTE question que tu as posée !

A+
Yannick.





  

Répondre à