A B C
A F G
A F M
A R F
Name: A
Name: 1
------
------
Name: B
Name: 1
------
------
Name: C
Name: 1
------
------
Name: A
Name: 1
------
------
Name: A
Name: 2
------
------
Name: F
Name: 1
------
------
Name: G
Name: 1
------
------
Name: A
Name: 3
------
------
Name: F
Name: 1
------
------
Name: M
Name: 1
------
------
Name: A
Name: 4
------
------
Name: R
Name: 1
------
------
Name: F
Name: 2
------
Campbell Ritchie wrote:Welcome to the Ranch
Did you mean to have return in the middle of a loop? You know that will terminate the whole method?
Why have you marked everything static?
Why are you using a for loop in the second method rather than a for‑each loop?
Did you mean to start the counter at 1 in the last method? When you get there you have not seen anything yet, so shouldn't it be 0?
Did you know you can pass a String to a Scanner and let it split on spaces rather than using String#split? Did you realise you can get wrong results from that regex (single space) if you have any double spaces in your input?
Matthew Brown wrote:I'm not sure if it explains exactly what you are seeing, but I can see one mistake. Look at lines 33/34. You create two Index objects, add one of them to the list, and return the other one.
So fix that and then see what the output looks like.
Unrelated to your specific problem, you might want to look at the HashMap class. That will make your lookup simpler, because it allows you to index your collection by a string, so you don't have to iterate through it each time.
Rob Craigson wrote:I'll be sure to pay it forward (if I can!)
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Except possibly in beerWinston Gutkowski wrote: . . . No bribes allowed on JavaRanch. . . .
I RELEASE YOU! (for now .... ) Feel free to peruse this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
|