aspose file tools*
The moose likes Beginning Java and the fly likes Array copying or assigning? Are they same? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Array copying or assigning? Are they same?" Watch "Array copying or assigning? Are they same?" New topic
Author

Array copying or assigning? Are they same?

Xiaolong Bao
Greenhorn

Joined: Jun 17, 2013
Posts: 16

Good day guys....

Please can anybody explain me:

what is the essential of this statement: char[] chars = createArray();

The array chars gets an returned array from the createArray() method,
is this an array copying or simply an assignment?
Do the arrays 'chars' and 'lowercaseLetters' point to the same memory location or they are two independent arrays??

Thanks!!!



Moving on is a simple thing, what it leaves behind is hard. You know the sleeping feel no more pain, and the living are scarred. ---A Tout Le Monde by Megadeth
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4388
    
    8

Hi Xiaolong. Welcome to the Ranch!

Arrays in Java are reference types. So the createArray() method is returning a reference to the array created - only one actual array exists in memory.

You can confirm it by looking at the following output, which makes two variables pointing to the array, then modifies it via one and checks to see if it's affected what the other reference sees:
Xiaolong Bao
Greenhorn

Joined: Jun 17, 2013
Posts: 16

Matthew Brown wrote:Hi Xiaolong. Welcome to the Ranch!

Arrays in Java are reference types. So the createArray() method is returning a reference to the array created - only one actual array exists in memory.

You can confirm it by looking at the following output, which makes two variables pointing to the array, then modifies it via one and checks to see if it's affected what the other reference sees:


Hi Matthew,

I got the point, really appreciate your reply.

There's so much to learn for me....I just need to keep going...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Array copying or assigning? Are they same?