File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes Arrays Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Arrays" Watch "Arrays" New topic


Vidya Ramachandran

Joined: Nov 04, 2005
Posts: 24
Suppose we have 2 arrays arr1 and arr2 of different lengths, is it possible to say

arr1 = arr2 where arr1.length < arr2.length
Paul Clapham

Joined: Oct 14, 2005
Posts: 19973

Yes, that is a valid assignment. Assuming the arrays are of the same type, that is.
Garrett Rowe
Ranch Hand

Joined: Jan 17, 2006
Posts: 1296

Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peter
Vidya Ramachandran

Joined: Nov 04, 2005
Posts: 24
thanks paul

can you tell me how it works.. i mean how is it dealt with becoz arr1 is of lesser length that arr2
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
You can declare an array variable with no size:

String[] tokens;

Now that doesn't point to anything at all yet. But we can make it point to any sized array we like

tokens = arrayOfFive;
tokens = arrayOfTen;

All the tokens variable knows is that it points to an array. The actual array we point to has a size and occupies an amount of memory that depends on the size.

Does that make sense? The ever popular Cup Story over at the campfire is good reading on this kind of thing, too.

A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Vidya Ramachandran

Joined: Nov 04, 2005
Posts: 24
thanks stan james
I agree. Here's the link:
subject: Arrays
It's not a secret anymore!