This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
Suppose I have an array containing elements that are related to its indexes, but I don't need (won't ever have to) access all of its elements. For example, I may never need to access the zeroth element. Are there any "rules of thumb" for when to use any one of these in preference to the others:
Thanks!
Marilyn de Queiroz
Sheriff
Joined: Jul 22, 2000
Posts: 9033
10
posted
0
I wonder if the second choice will even compile. The advantage of the third over the first is that you avoid creating a String object. Any time you can avoid creating extra unnecessary objects, you're better off.
JavaBeginnersFaq "Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Pauline McNamara
Sheriff
Joined: Jan 19, 2001
Posts: 4011
posted
0
Hey Jinny. This question sounded a little familiar so I did a quick search on "placeholder".
And now I know why it sounded familiar (and why I like this question so much)...
...I asked it myself some time ago, he he.
Jinny Morris
Ranch Hand
Joined: Apr 29, 2007
Posts: 101
posted
0
Yes, the second choice will compile and run; I've used it. The reason I asked the question is that the instructor's solution for one of the "java in general" assignments uses 2 arrays: the first choice is used in one of the arrays and the third choice is used in another of the arrays. So I wondered ...
Marilyn de Queiroz
Sheriff
Joined: Jul 22, 2000
Posts: 9033
10
posted
0
What happens if you use the 3rd choice in the array that the instructor uses the first choice in?
Marilyn de Queiroz
Sheriff
Joined: Jul 22, 2000
Posts: 9033
10
posted
0
Originally posted by Jinny Morris: Yes, the second choice will compile and run; I've used it.
Ah, yes. After thinking about it some more, I can see that it would.
Jinny Morris
Ranch Hand
Joined: Apr 29, 2007
Posts: 101
posted
0
I think it's C-ish or VB-ish or something like that - nicely convenient, in any case (although perhaps not as "readable" as null?)