Pseudocode:
In Loop for n-iterations {
// I am doing a check below
if (params.contains("test") {
}
}
Will the string test
be created as object n
times?
Pseudocode:
In Loop for n-iterations {
// I am doing a check below
if (params.contains("test") {
}
}
Will the string test
be created as object n
times?
No.. "test"
is a String literal , so it goes into the String constants pool and will be reused for all future accesses of "test". if you do new String("test")
(bad way of creating String) ,then several instances of the String "test" will be created - one for each iteration
No. "test"
is a unique object, that is stored in the String pool. It's thus even the same object as any other "test"
literal you might have elsewhere in the application.