aspose file tools*
The moose likes Cattle Drive and the fly likes array placeholders Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » This Site » Cattle Drive
Bookmark "array placeholders" Watch "array placeholders" New topic
Author

array placeholders

Jinny Morris
Ranch Hand

Joined: Apr 29, 2007
Posts: 101
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: 9053
    
  12
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: 4012
    
    6
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
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: 9053
    
  12
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: 9053
    
  12
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
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?)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: array placeholders