Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Arrays  RSS feed

 
macca Mason
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, I am having a problem with arrays. I want to put five varables in array [0]. Can this be done.



[ May 13, 2004: Message edited by: macca Mason ]
[ May 13, 2004: Message edited by: macca Mason ]
 
fred rosenberger
lowercase baba
Bartender
Posts: 12542
48
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
an array is a collection of one type of thing. each slot can only hold 1 thing. So, as written, you have a couple problems...

1) you are trying to put more than one thing into the same slot
2) the things you are trying to put in are not all of the same type.

Now, there are ways around this. You could define a class of type Car or something. this class would have as its member variables the 6 or so things you want to store (i.e. manufacturer, model, etc).

you can then make an array of Cars. once you get the six pieces of data into a Car object, you can put that into your arrray[0].
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!