Q:

How to access for-each loop variable in other class

I am a a newbie to java. I am learning to use for-each loop for iterating over arraylist.
  for(String s:list){
my code
}

I want to access variable s in another class of same package. Event after making method static I am not able to do so. 
I also tried by initializing variable as below:
      static String s=null;

    for(s:list){
    my code

}

This code is also not working. Please help me to know correct way to access variable 's' in another class

A:

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);
}

