• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

ArrayList indexOf

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
What's wrong? Where are you going? Stop! Read this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic