How to access for-each loop variable in other class [closed]

If you want to pass the variable to another class, pass the variable as an agrument to that class’s method.

Eg:-

Class2 class2 = new Class2();
for(String s : list){
    class2.method(s);
}

Leave a Comment