0

i'm trying get the content of an Arraylist but it only has the last value but repeated for the size of the array ( if i add 5 object, it will only show the last object 5times). and i don't know why.

where i insert data

try{
            JSONArray json = new JSONArray(sb.toString());
            Countries coun = new Countries();
            for(int i=0; i < json.length(); i++) {
                JSONObject jsonObject = json.getJSONObject(i);

                //          Log.i(TAG, "Nom Pays :  " + jsonObject.get("name"))
                coun.setNom((String) jsonObject.get("name"));
                coun.setCode((String) jsonObject.get("code"));

             //   Log.i(TAG, "- - - "+ coun+"- - - " );

                country.add(coun);
            }
        }catch (JSONException je){
            je.printStackTrace();
        };

        Log.i(TAG, "- - - "+ country+"- - - " );

        Iterator it= country.iterator();
        while (it.hasNext()){
            Log.i(TAG, "- - - "+ it.next()+"- - - " );
        }

and when i try to see the data on the Array like that " Log.i(TAG, "- - - "+ country+"- - - " ); " it show me this enter image description here

and with the iterator it give the same result. I've put the instaciation of the ArrayList on the class

private ArrayList<Countries> country = new ArrayList<Countries>(); 

i don't know why it give me that result

Could someone give me a hint pls

0 Answers0