我有這樣的代碼如何將值從我的循環中放入arraylist中?
for (int i = 0; i < friendslocations.length(); i++)
{
JSONObject c = friendslocations.getJSONObject(i);
String friendName = c.getString(TAG_FRIENDNAME);
System.out.println("friend name " + friendName);
String friendLocation = c.getString(TAG_LOCATION);
System.out.println("friendlocation" + friendLocation);
}
,保存着印刷我我想要的值。
但我需要知道如何將來自此循環(friendname和friendloaction)的值放入數組列表中,其中每個索引包含此(friendname,friendlocation)。
那麼我該如何做到這一點?
你剛纔在10分鐘前提問這個問題。首先創建一個數組。然後在循環中將這些項目添加到數組中。 – user1336827
如果你想保持兩個字段彼此創建一個類,然後創建一個類'Arraylist' –