This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Java in General and the fly likes Array Indexing Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Array Indexing" Watch "Array Indexing" New topic

Array Indexing

Khurram Chaudhary

Joined: Aug 08, 2002
Posts: 6
I have got an array and I want to create an other array from that array by specifying start and end index.
I receive start value and number of values require from a client. I workout values require by
int endValue = valueRequire - startValue;
then create an array, of "endValue" length;
new Array[endValue];
then put two arrays in a loop and populate the newly created array by reading the original array.
This is very very bad, it works for some numbers and fails for others. Can't we just pass in two numbers(start and end) for an array and it gives back a sub array.for example
AnyType subArray[] = actualArray(1,5);
Can anyone suggest a better way of doing this.
Khurram Chaudhary

Joined: Aug 08, 2002
Posts: 6
I have found the answer, convert the array into a List and then use List.subList(startValue, endValue);
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451

[ June 27, 2003: Message edited by: Michael Morris ]

Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
I agree. Here's the link:
subject: Array Indexing
It's not a secret anymore!