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 -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -