• Post Reply Bookmark Topic Watch Topic
  • New Topic

Replacing old values with new values  RSS feed

 
Brian Thayer
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For a school assignment the class was asked to modify some existing code that we had done earlier so that on of our methods would call another method to see if a certain text file had any duplicate entries, and replace any old values with the newer values. We had already written one method called ipos to read and display all of the entries in the file. We had also written a method called addAttr to add any missing values. We were asked to modify the addAttr method using ipos to replace the old value of each of the attributes in the file with the new attribute. We were told to use an if statement. The code I have is below, I know that what I have is what my professor wanted, I am simply unsure of what to put in the if block to replace old values with the new ones that ipos finds.



The first block is the addAttr method that is being modified. The second method is the ipos method that scans the config file line by line and returns each key and its associated value. If you need any additional information please let me know and I will try to answer to the best of my ability. If you need to see the rest of the code that is fine as well. Just let me know and I'll post the code in its entirety.
 
Wouter Oet
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi and welcome to the Javaranch.

Is it correct that ipos() returns the index location of the attribute in the array? In that case just replace the value at that location without incrementing numCfg.
By the way: why don't you use an ArrayList to store your values that way you have access to handy method such as contains().
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!