0

I have an ArrayList Contain Strings as follow

1, 200, 2 , 434 , 3 , 400 , 4 , 500 ............................... and so on

how i can remove the number 1,2,3,4

i tried the followinh code but its not worrking

 for (int i=0;i<content.Size();i++){
                  if(i%2== 0 ) // if the index is even
                      content.remove[i] 
                      }

it gives me the following
1,200,434,3,40.............

and what i want is

200,434,400,500

4
Contributors
9
Replies
10
Views
4 Years
Discussion Span
Last Post by JamesCherrill
0

Does removing an element change the locations of the following elements?
Try scanning into the list from the end so the indexes of the remaining elements don't change.

0

it seems changing the loction is the problem .
i tried to scan from the end by this code

 for (int i=list.size(); i>=0;i--){
                  if(i%2==0)
                  list.remove(i);
              }

but it gives me the following error
Exception in file readingjava.lang.IndexOutOfBoundsException: Index: 48, Size: 48

0

i can now remove the wanted element ;
but how ican change arrayList type from String to Float

0

How do you declare the arraylist now?
And do you mean change the way it's declared, or convert its contents from Strings to Floats?

0

I mean to convert its content From String to float

0

You won't find a method that converts a whole arraylist in one go. You;ll have to take the Strings one at a time, convert them, and add them to the Float ArrayList.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.