阅读背景:

搜索Java ArrayList并返回元素位置 - indexOf()不起作用。

来源:互联网 

I have been writing a program that asks a user to input a name, ticket type and fine. The user input is being stored into a text file. I am reading the text file into an array named 'list' and prompting the user to search for a 'keyword'. I am storing the keyword as a String = keyword. When I use a println(list.indexOf(keyword)), I am getting a "-1" output even though the keyword being searched for is returning found! That is where I am stuck...I'm not sure why the indexOf() method cannot find the element but my search for the keyword is able to. Any help would be greatly appreciated! Note: My end goal is to search for the "keyword", find the elements location and return true. I will then be asking the user for a new name, ticket type and fine. I will replace the information in the text file and write the new information to the text file mentioned earlier. Thanks in advance for the input. Code is included (I'm new to Java so please be nice :0) I will clean the code up once I finish the program. I have been writing a program that asks a user




你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: