I have a List and it has duplicate value, I want to leave out the duplicate values from that and filter only the single values as,
Current output is {a, a, a, b, b, c, c, d, d, d, d}
and I want to change it and get the output as {a, b, c, d}
.
This is the code I'm using right now to get the current output,
List<String> pickupOutlet = new ArrayList<String>();
@Override
public void onTaskCompleted(JSONArray responseJson) {
// TODO Auto-generated method stub
try {
for (int i = 0; i < responseJson.length(); ++i) {
JSONObject object = responseJson.getJSONObject(i);
Log.i("OutletName", object.getString("OutletName"));
pickupOutlet.add(object.getString("OutletName"));
}
} catch (JSONException e) {
e.printStackTrace();
}
}
Can anyone help me how to achieve it.
UPDATED
Current code
This worked for me
for (int i = 0; i < responseJson.length(); ++i) {
JSONObject object = responseJson.getJSONObject(i);
if (!pickupOutletDuplicates.contains(object.getString("OutletName"))){
Log.i("OutletName", object.getString("OutletName"));
pickupOutletDuplicates.add(object
.getString("OutletName"));
}
}