Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Array Indexing

 
Khurram Chaudhary
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have found the answer, convert the array into a List and then use List.subList(startValue, endValue);
 
Michael Morris
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

[ June 27, 2003: Message edited by: Michael Morris ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic