Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

array question

 
Scott Pocane
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok if i want 3 different ellements in one array how would i go about doing that.
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What do you mean by three different elements? Three different kinds of objects? You can use an Object array to hold any kind of objects, like
Object[] myArray = { "A string", Color.RED, new Point(1, 2) };
But if you're going to count on a certain object being in a certain position (and I know that's what you're going to do!) then don't use an array -- define a new class to hold the objects as member variables.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic