I have a ArrayList with objects. When I try to get the properties of the objects in the ArrayList, the returned variable isnt exactly the value, which i before set to the variable. For example, when I try to compare the returned variable, variable type "String" isnt working. But when I print the value of the returned variable, it seems everything is working.
//Class:
public class obj{
public String name;
public obj(String name){
this.name = name;
}
}
//Add to List:
ArrayList<obj> objs = new ArrayList<obj>();
objs.add(new obj("txt"));
//Get Value:
String name = objs.get(0).name;
//Not working:
if (name == "txt"){
println("...");
}
//But working:
println(name); //same
if (name.charAt(0) == 116){ //"t"
println("working");
}
I tried:
- getter/setter methods are resulting in the same
- converting the returned var with a function which takes every char of the returned var, because the .length() is working, to a new String, containing every single character of the returned variable.
- creating a "toString()" method which returns the name of the object.