i created a class with the following definition
public class RegionsWithConstituency {
String reg_name;
String const_name;
public void setRegionName(String reg_name)
{
this.reg_name = reg_name;
}
public String getRegionName()
{
return reg_name;
}
public void setConstituencyName(String const_name)
{
this.const_name = const_name;
}
public String getConstituencyName()
{
return const_name;
}
@Override
public String toString()
{
return const_name;
}
}
i populated this class as follow:
ArrayList<RegionsWithConstituency> region = new ArrayList<RegionsWithConstituency>();
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject jsonObject = jsonArray.getJSONObject(i);
RegionsWithConstituency reg = new RegionsWithConstituency();
reg.setRegionName(jsonObject.optString("Region"));
reg.setConstituencyName(jsonObject.optString("Constituency"));
region.add(reg);
}
i want to find the constituency name based on region name and save the result into a ArrayList of String. an example will be something like that
for (int i = 0; i < region.length(); i++) {
if (regionList.Contains(region)){
listofString.add(region.getConstituencyName())
}
}
i am a c# background , i know how to achieve this one in c# but not in java, so i need a help about that , feel free to ask any question if u don't get my problem properly.
equals()andhashcode().