This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Arrays" Watch "Arrays" New topic
Author

Arrays

Vidya Ramachandran
Greenhorn

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
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

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
Yes.


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
Greenhorn

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
Greenhorn

Joined: Nov 04, 2005
Posts: 24
thanks stan james
 
 
subject: Arrays
 
Similar Threads
array
Adding elements of two arrays
(String[] args) vs. (String args[])
How do I cast from Vector to String Array?
Printing in Array in Ascending order