Re: Difference between String variable and String Class definition
- From: Duane Evenson <duane6@xxxxxxx>
- Date: Mon, 27 Mar 2006 23:34:41 GMT
On Mon, 27 Mar 2006 13:41:45 -0800, vahid.xplod wrote:
hi ,
can anyone tell me what is difference between String variable and
String class definition.
for example :
String variable ---> String = "java";
String Class ---> String = new String("java");
in two example above, i want to know that every two definition are same
as each other about memory allocation or not ?
The first line allocates memory for the literal "java". It then points the
variable to this location.
The second line allocates space for the literal. It then creates a new
String class. It copies the string from the first place to the new place
in memory. Finally, it points the variable to that location.
All you do in the second example is create more work for the computer
and use up more memory (until the next garbage collection).
Consider what
String var - new String(new String(new String("java")))
would do.
....
A series of memory allocations would occur with "java" being copied
from one place to the next.
.
- Follow-Ups:
- Re: Difference between String variable and String Class definition
- From: James McGill
- Re: Difference between String variable and String Class definition
- From: Tom Fredriksen
- Re: Difference between String variable and String Class definition
- From: Roedy Green
- Re: Difference between String variable and String Class definition
- From: Patricia Shanahan
- Re: Difference between String variable and String Class definition
- References:
- Difference between String variable and String Class definition
- From: vahid . xplod
- Difference between String variable and String Class definition
- Prev by Date: Re: who can tell me why
- Next by Date: Re: Problem with Ant jars
- Previous by thread: Difference between String variable and String Class definition
- Next by thread: Re: Difference between String variable and String Class definition
- Index(es):
Relevant Pages
|