Thread: Bounded Array
View Single Post
  #4 (permalink)  
Old 01-04-2008, 05:27 AM
gibsonrocker800's Avatar
gibsonrocker800 gibsonrocker800 is offline
Senior Member
 
Join Date: Nov 2007
Location: New York
Posts: 143
gibsonrocker800 is on a distinguished road
Send a message via AIM to gibsonrocker800
Whenever i want to have a group of objects of a type other than String or ints or doubles, i use ArrayList. It's better in the sense that it doesn't have a fixed length. When you have an array there can only be a certain number of objects in that array, but in an ArrayList you can add as many as you'd like.

I also like using HashSet when order doesn't matter, and when you want it to not repeat elements. A while ago i started on my first real test of my logic skills: a Sudoku game, and, my knowledge didn't really offer a solution to how i could check if the user won. But, when i learned about HashSets it completely solved my problem. Basically what i did was, add all the numbers (of a row, column, or square) the user entered into the HashSet, and if the size of the HashSet is less than 9, they didn't win (there's a method to check the rows, colums, and squares). The reason for this is, if there are not 9 number in the HashSet, that means that the user repeated a number (and HashSets silently ignore when a duplicate element is an argument of the add method), which means the user didn't win the game.

So yeah i mean i guess everyone has their own style. Different people like using different classes that do virtually the same thing. Its just a matter of preference.
__________________
//Haha javac, can't see me now, can ya?
Reply With Quote