• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Array Indexing

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have found the answer, convert the array into a List and then use List.subList(startValue, endValue);
 
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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