String array java -


when create string array , give string values elements in array pointer string object or hold object itself. in below code each of element i.e. days[0] pointer string objects holds string value or object in array. each element point different string object or same object? how differ primitive type array int[] test= new int[6], these hold int values. thanks

string[] days = new array[7]; days[0] = "sunday"; days[1] = "monday"; days[2] = "tuesday"; days[3] = "wednesday"; days[4] = "thursday"; days[5] = "friday"; days[6] = "saturday"; 

when create string array , give string values elements in array pointer string object or hold object itself.

object arrays contain references objects not objects themselves.

does each element point different string object or same object?

in example each array element references different string , different object. if let's you'd set days[6] = "sunday"; days[0] , days[6] reference same interned string (because literal), in case of days[6] = new string( "sunday" ); both elements reference different equal strings.

how differ primitive type array int[] test= new int[6], these hold int values.

yes, primitive arrays hold values directly, since there no objects reference.


Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -