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

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.

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

Should be for(int i=list.size()-1;i>=0;i--)

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

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?

I mean to convert its content From String to float

The Float class has a method to convert a String to a float

but this method doesnt work on ArrayList

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.