0
How is an array a collection of variables?
this was a definition relating to c++ . becuase im currently learning java and i see them as collection of elements/values rather then variables i see a variable as somthing you would initialize a value too. or does it mean that you can create an array of variables with you can assign afterwards? like this.. String x[] = {"h","w"}; x[0] = "hello"; x[1] = "world"; System.out.println(x[0] + " " + x[1]); still look like values to me and x being the variable
4 Antworten
+ 7
@David
int x = 6;
int y = 7;
int[] arr = new int[] {x, y};
Hope I didnt get any syntaxs wrong. But thats about it.
+ 6
Well it depends. But generally I would say that its a collection of a values with the same datatype.
It can be a collection of variable if all you put in your arrays are variables. (And variables store values, so it can be a collection of value too :V .)
+ 1
@Wen Qin can you show my an example of an array holding variables with values please
+ 1
ooohhh i didnt know you could do that! well... that clears things up lol