How to print a specific object by field id within an array list of objects? -


i have location class stores multiple location objects, parsed in json file. @ moment can print out all locations in list using tostring() method. output looks this:

http://hastebin.com/eruxateduz.vhdl

this example of 1 of loctions within list:

location [location=null, id=3, description=you @ battlefield of jerusalem. in awe of surroundings, see exit west., weight=100, name=jerusalem, exit=[exit [title=hattin, direction=west]]],  

but i'm wondering how can print out specific location within list field value id, example loction id="2"?

i'm thinking override tostring method created take input of id, , print corresponding location object, not sure how print 'id':

if(locationobject.getid() == "2") {       //do } 

this pojo location class stores objects:

public class location {      private location[] location;      private int id;      private string description;      private string weight;      private string name;      private exit[] exit;      private boolean visited = false;     private boolean goallocation;     private int approximatedistancefromgoal = 0;     private location parent;         public location[] getlocation() {         return location;     }      public void setlocation(location[] location) {         this.location = location;     }       public int getid() {         return id;     }      public void setid(int id) {         this.id = id;     }      public string getdescription ()     {         return description;     }      public void setdescription (string description)     {         this.description = description;     }       public string getweight() {         return weight;     }      public void setweight(string weight) {         this.weight = weight;     }      public string getname ()     {         return name;     }      public void setname (string name)     {         this.name = name;     }      public exit[] getexit() {         return exit;     }      public void setexit(exit[] exit) {         this.exit = exit;     }      @override     public string tostring() {         return "location [location=" + arrays.tostring(location) + ", id=" + id                 + ", description=" + description + ", weight=" + weight                 + ", name=" + name + ", exit=" + arrays.tostring(exit)                 +"]";     }    } 

try checking id's

if(locationobject.getid() == "2") {       system.out.println(locationobject.getdescription()); } 

Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -