aspose file tools*
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 Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Array Indexing" Watch "Array Indexing" New topic
Author

Array Indexing

Khurram Chaudhary
Greenhorn

Joined: Aug 08, 2002
Posts: 6
Hi,
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.
Thanks
Khurram.
Khurram Chaudhary
Greenhorn

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: http://aspose.com/file-tools
 
subject: Array Indexing