I am wondering if there is a way to print the index of the array based on the index of the array
SCJP6
Jason Irwin wrote:Sounds like a better solution would be to forget arrays and pick the most appropriate Collection for the problem you are trying to solve (a simple ArrayList would probably do it).
I am wondering if there is a way to print the index of the array based on the index of the array
I do not follow that at all, but I will admit to having serious brain-fade today...
Mike Osterhout wrote:ya i guess that was a bit confusing.
I am just trying to print the index of the array as a number, while getting that number based on the actual index rather than the value of the index.
because doing this system.out.println(newinv[i]); //would print the value and not the index
SCJP6
"access/print the index of the array based on the index of the array".
// There must be some way to make the index equal to i if the target is found, but I can't think of it just at the moment.
SCJP6
Jason Irwin wrote:
"access/print the index of the array based on the index of the array".
I think you may not be using the word "index" correctly.
The only way to access an array is by index. That's it. Not by value, not size, not memory offset or anything wild. Just index. That's your lot*.
When you access an array by its index what you get back (assuming it's not out of range or anything) is the value at that index. That's it. Nothing else. Not even the index is returned to you, you just get the value.
Do you understand now why you request make no sense?
Do you mean you want to iterate (loop - like with a for, while or do-while) over the array, printing out the index and the value in the array at that index?
*There are some methods on certain classes that can do fancy things in memory with native code...but I don't think we need to get into that just now!
I've remembered how to do it nowJason Irwin wrote:
// There must be some way to make the index equal to i if the target is found, but I can't think of it just at the moment.
Yeah Campbell....sure.
Yes I wanted to iterate over the array to print the indexes.
Mike Osterhout wrote:the indexes of the array.
Mike Osterhout wrote:the indexes of the array.
SCJP6
So he really wants something different?Jason Irwin wrote:
. . . I can't think of it just at the moment.
Yeah Campbell....sure.
SCJP6
If the discussion has gone on this long it sometimes becomes necessary to give a straight answer.Jason Irwin wrote: . . .
I know giving full answers is bad form, but it's about the only way I can think of getting across what an index actually is.
SCJP6