java - Foreach and making new objects gives nulls -


i have piece of code:

public class main {     static string strings[];      public static void main(string[] args) {         strings = new string[10];         (string s : strings) {             s= new string("test");         }          (string s : strings) {             system.out.println(s);         }     }  } 

why of strings still contain null instead of "test"?

your enhanced statement (for-each loop) equivalent to:

t[] = strings; (int = 0; < a.length; i++) {     string s = a[i];     s = new string("test"); } 

so problem similiar case:

string = null; string b = a; b = new string("test"); system.out.println(a); // null 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Socket.connect doesn't throw exception in Android -

iphone - How do I keep MDScrollView from truncating my row headers and making my cells look bad? -