Newsletter sign-up
View all newsletters

Enterprise Java Newsletter
Stay up to date on the latest tutorials and Java community news posted on JavaWorld

Sponsored Links

Optimize with a SATA RAID Storage Solution
Range of capacities as low as $1250 per TB. Ideal if you currently rely on servers/disks/JBODs

Object-oriented language basics, Part 5

The root of all classes

  • Print
  • Feedback

Page 4 of 6

first
second
s == t: false
true
10
20
30


As you can see, Java automatically completes everything required to duplicate an array. No fuss, no muss! However, arrays are shallowly cloned. That is why s [0] and t [0] refer to the same String object. To properly duplicate the objects referenced by the String array's elements, you must use deep cloning. And how do you do that? I've left you that task as a homework exercise.

  • Print
  • Feedback

Resources