I made an Custom Class which name is (ObjClass).
I insert Custom Class name instead of value in LinkedHashMap. Like the following:
LinkedHashMap map = new <> LinkedHashMap;
I have following getter and setter in ObjClass, there names are
private String Name;
private int level;
private String parent;
Now the problem is when i try to get the key by comparing of specific field like name it didn't execute.
My code is following:
public class Practice {
LinkedHashMap<Integer,ObjClass> map = new LinkedHashMap<>();
public void addd(){
int a = 10;
int b = 20;
int c = 30;
ObjClass bb = new ObjClass();
bb.setName("COLOR");
bb.setParent("ROOT");
bb.setLevel(1);
bb.getName();
bb.getParent();
bb.getLevel();
map.put(a, bb);
bb.setName("RED");
bb.setParent("COLOR");
bb.setLevel(2);
bb.getName();
bb.getParent();
bb.getLevel();
map.put(b, bb);
bb.setName("WHITE");
bb.setParent("COLOR");
bb.setLevel(2);
bb.getName();
bb.getParent();
bb.getLevel();
map.put(c, bb); here
// the problem is in the for loop i try to get the key of "red" which is 20 but my loop is not working..
for (Map.Entry<Integer, ObjClass> entry : map.entrySet()) {
if(entry.getValue().getName().equals("RED"))
{
System.out.println("yes"+ entry.getKey());
}
}
System.out.println(" "+map.size());
}
public static void main(String[] args) {
Practice pp = new Practice();
pp.addd();
}}