I am trying to find a way to convert a String value into a variable. Is this possible?
For example:
String str = "chicken";
/*Then have it so I can do this*/
int chicken = 2;
I know I can just type the variable name in, but I want it so a user input, which is a String, can be converted into a variable name after a button is clicked. Here is what I mean:
/*This is in JavaFX*/
Button button = new Button("Click Me");
TextField userText = new TextField();
ArrayList<List> randomList = new ArrayList<>();
/*When button is clicked*/
button.setOnAction(e -> {
ArrayList<List> "The user's text" = new ArrayList<>();
randomList.add("The user's text");
});
"The user's text" is the user input being used as a variable name.
P.S. = Please don't recommend HashMaps or Maps unless there is no other way. I've already started with ArrayLists.