aspose file tools
The moose likes Beginning Java and the fly likes ArrayList indexOf Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "ArrayList indexOf" Watch "ArrayList indexOf" New topic
Author

ArrayList indexOf

tk harvey
Greenhorn

Joined: Nov 15, 2007
Posts: 4
My goal is to write a report generator that keeps a running total of alarm messages in a .csv file. I have condensed my original code down to this snippet that is used to see if an alarm message (read from an input file as �LineIn�) is already in my list, and if so, use its indexOf value for updating the running-count (also contained on the same comma-delimted line as the message) later on.

I�m at a loss to understand why the indexOf doesn�t work as I expect and my frustration has grown to the point where I�m ready to ditch this and write it in PERL/ksh.

The AHC.get returns exactly what I expect, the 4th line of my .csv file (and it indeed contains the string "CarbonAlarm"), but the AHC.indexOf always returns -1. Based on what I have read here in the Saloon, it probably has something to do with the �String LineIn�. I would be forever in debt to someone who would please explain to me what is going on.
EEEEKS!! where did my formatting go after cut&paste???
I hope ya'll can read this...

now, i guess i'd better go find the FAQ about formatting...
[ November 15, 2007: Message edited by: tk harvey ]
Adam Schaible
Ranch Hand

Joined: Oct 04, 2007
Posts: 101
First thing is I would also refer to the list by it's interface, List - so
List ACH = new ArrayList();

You mention that the fourth line of the csv contains the string "CarbonAlarm" - but if you read the javadoc for the indexOf method you will see:



So unless the fourth line of your CSV .equals("CarbonAlarm"), the indexOf method will not return the that index.
[ November 15, 2007: Message edited by: Adam Schaible ]
tk harvey
Greenhorn

Joined: Nov 15, 2007
Posts: 4
Oh okay, it's the old "Returns:the index of the first occurrence of the *entire 10-field* argument in this list;" usage. My face is red... THanks! for your help!
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: ArrayList indexOf
 
Similar Threads
Problem with parseInt and entering in array
Why is my loop not working properly?
NullPointerException problem
Not able to send a mail using JAVA code
Collections.shuffle problem