Results 1 to 2 of 2
- 06-29-2011, 05:23 PM #1
Member
- Join Date
- Jun 2011
- Posts
- 1
- Rep Power
- 0
String -> variable (setting variables from parsing a text file)
I'm trying to set variables from a text file. If the string I get is exactly the same name as a variable in my class, can I set it directly? For example:
int myValue;
String s = "myValue";
int i = Integer.parseInt("42");
Is there a better way to assign the value besides doing:
if (s.equals("myValue"))
myValue = i;
- 06-29-2011, 05:46 PM #2
Moderator
- Join Date
- Jul 2010
- Location
- California
- Posts
- 1,605
- Rep Power
- 5
The best way is the way that works. Does this work for what you are trying to accomplish? There are quite possibly many different way to accomplish what you are doing, the 'best' way is quite relative to what you are trying to accomplish in the grand scheme of things.Is there a better way to assign the value besides doing:
Similar Threads
-
Store links in text file and read into variables
By africanhacker in forum New To JavaReplies: 1Last Post: 03-31-2011, 05:18 PM -
setting path and classpath variables from batch file -
By manojsingh.manoj@gmail.co in forum Advanced JavaReplies: 1Last Post: 09-15-2009, 11:50 AM -
remove variables/line in a text file
By ddatta8 in forum New To JavaReplies: 2Last Post: 01-04-2009, 03:05 AM -
append variables to a text file
By ddatta8 in forum New To JavaReplies: 2Last Post: 01-02-2009, 10:17 AM -
building file and variable names from variables
By madad2005 in forum New To JavaReplies: 2Last Post: 07-18-2007, 04:47 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks