Can someone explain how I would make a method for an arrayindexlist - removerange(int n, int k) where n is the from index (inclusive) and k is the to index(exclusive).

Thanks

Printable View

- 02-27-2012, 03:23 PMstuckonjavaArraylist index question
Can someone explain how I would make a method for an arrayindexlist - removerange(int n, int k) where n is the from index (inclusive) and k is the to index(exclusive).

Thanks - 02-27-2012, 03:41 PMJosAHRe: Arraylist index question
Remove the elements from the end, i.e. remove element k-1, k-2 ... n, starting at element k-1.

kind regards,

Jos - 02-27-2012, 03:56 PMstuckonjavaRe: Arraylist index question
I don't understand,

If we have the array with 3,8,6,9,19 and we want to remove 6 and 9 that would be removeRange(3,5) so the new array is 3,8,19.

how do i do this so that the 3rd and 4th index are removed and the 19 is brought to index 2? - 02-27-2012, 04:01 PMJosAHRe: Arraylist index question
- 02-27-2012, 04:07 PMstuckonjavaRe: Arraylist index question
How would i do it for an IndexList, what is the difference in the method between that and the normal one.

ArrayIndexList<Integer> a = new ArrayIndexList<Integer>(); - 02-27-2012, 04:56 PMJosAHRe: Arraylist index question
- 02-27-2012, 10:17 PMstuckonjavaRe: Arraylist index question
public E remove(int r){

throws IndexOutOfBoundsException{

E temp = A[r];

for (int i =r; i<size-1; i++)

A[i] = A[i+1]

size--

return temp

Could you tell me whether this is correct for removing a single element?

Thanks

} - 02-27-2012, 11:07 PMstuckonjavaRe: Arraylist index question
anyone?

- 02-27-2012, 11:33 PMstuckonjavaRe: Arraylist index question
please

- 02-27-2012, 11:47 PMstuckonjavaRe: Arraylist index question
whats happened to everyone

- 02-28-2012, 12:35 AMstuckonjavaRe: Arraylist index question
can someone confirm whether this would work please:

public E removeRange(int from, int to)

throws IndexOutOfBoundsException{

for(int i = to - 1; i >= from; i--)

{

A[i] = A[i + 1];

size--;

}} - 02-28-2012, 08:00 AMJosAHRe: Arraylist index question
What did your compiler say about it? As far as I can see your code doesn't compile. Also, is 'size' a member variable in your own class? Is 'E' the type of the elements in your array 'A'? Besides all that, your code makes sense to me (logically). Test it.

kind regards,

Jos