• Post Reply Bookmark Topic Watch Topic
  • New Topic

do something with an unused string variable  RSS feed

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi. I have a program that inputs a text file line by line. There are four columns in the text file, I've used String a, b, c, and d to store the information temporarily. In this program I use String b, c, and d, however String a has no use in the output file and is not used in the program at all, except during the input.

Is there a command I should be using to discard String a?

My IDE is telling me the value of the variable is not used, but the program runs properly besides that.
 
Ranch Hand
Posts: 859
Chrome IBM DB2 Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How are you parsing the String ?

If you are copy the array from array[0] => a, [1] => b etc.
then simply start at array[1] => b.

i wouldn't worry too much about it, you can always set a = null; if you're paranoid about memory.

WP
 
Sheriff
Posts: 22846
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not a "command" as such -- if the variable isn't being used, then just delete the declaration from your code.
 
Roger Weyersberg Ii
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
while(readFile.hasNext()){
String a = readFile.next();
String b = readFile.next();
String c = readFile.next();
String d = readFile.next();

this is how it reads, and then after this there is no use for String a again. Memory isn't really a concern in this scenario, I'm mostly concerned with learning the proper way to do it for future reference.
 
Paul Clapham
Sheriff
Posts: 22846
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One possibility:


But yes, you're correct, memory isn't an issue here. If you had meaningful variable names then it might be a reasonable idea to assign the first element to a variable which is never used, just for documentation. Or it might not. It's hard to say anything about what you should do in the case of a meaningless example. What you should do is meaning-dependent.
 
Roger Weyersberg Ii
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Paul, that makes sense
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!