How is an array a collection of variables? | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
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

14th Aug 2017, 10:22 AM
D_Stark
D_Stark - avatar
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.
14th Aug 2017, 3:54 PM
Wen Qin
Wen Qin - avatar
+ 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 .)
14th Aug 2017, 11:37 AM
Wen Qin
Wen Qin - avatar
+ 1
@Wen Qin can you show my an example of an array holding variables with values please
14th Aug 2017, 11:45 AM
D_Stark
D_Stark - avatar
+ 1
ooohhh i didnt know you could do that! well... that clears things up lol
14th Aug 2017, 4:46 PM
D_Stark
D_Stark - avatar