I have two variables that I'm trying to compare but the variable names are long and I'm trying to clean up my code, all the code here is just used as an example.
What I want to do is something like this:
if(objectOne.objectTwo.variableName1 == objectTwo.objectTwo.variableName1)
if(objectOne.objectTwo.variableName2 == objectTwo.objectTwo.variableName2)
...
and do this multiple times but every time change the number at the end of the string but I'm trying to do it like this:
for(int i = 0 ; i < 5 ; ++i) {
String firstString = "objectOne.objectTwo.variableName" + i;
String secondString = "objectTwo.objectTwo.variableName" + i;
if(firstString == secondString)
//more code
}
however this compares the Strings and I'm trying to use the Strings themselves as references to different variables is there any way of doing this?
EDIT: I'm looking to clean up the code but the main problem I'm having is if I had 100 variableNameNumber variables I would have to do 100 separate if statements, I'm trying to do it in a simple for loop as i increments the variable names get updated