dimanche 27 mai 2018

Why complete Arraylist is not getting printed through second for loop?

My complete arrayList is not getting printed through second for loop.(print statement highlighted by comment:second loop print statement),whereas its getting printed through first for loop.

What I am trying to accomplish.:Print the objects of arraylist except characters.[print first object regardless of character or any other object].

problem I am facing:Arraylist object '2' is not getting printed on console through second for loop.

code:

import java.util.ArrayList;

public class Test1 {

public static void main(String[] args) {
    // TODO Auto-generated method stub

    ArrayList al = new ArrayList<>();
    al.add('a');
    al.add('2');

    for(int i=0;i<al.size();i++){
        System.out.println("element enterd in for loop: "+al.get(i));
    }

    for(int i=0;i<al.size();i++){
        System.out.println("element enterd in for loop: "+al.get(i));     //second loop print statement

        if(al.get(i).toString().charAt(0)>=65 & al.get(i).toString().charAt(0)<=122){

            al.remove(i);
            continue;

                }
        }
    }

}

Help:please help me in figuring out where the issue.

Aucun commentaire:

Enregistrer un commentaire