ArrayList
의 요소 배열을 어떻게 얻을 수 있습니까? HashMaps
? 나는 그것에 대한 열쇠가있는 HashMap을 가지고있다. 값은 URL 주소입니다. 여러 HashMaps
은 ArrayList
에 저장됩니다. 내가 원하는 것은 모든 URL 문자열을 가진 array
입니다. 나는 그것이 어떤 조작으로 ArrayList
에서 추출 될 수 있다고 생각하기 때문에 내가 발견 한 해결책에 만족스럽지 않다.배열에 대한 HashMap 요소의 ArrayList
// Hashmap for ListView
ArrayList<HashMap<String, String>> itemsList = new ArrayList<HashMap<String, String>>();
// Creating JSON Parser instance
JSONParser jParser = new JSONParser();
jParser.execute(url);
try {
JSONObject json = jParser.get();
items = json.getJSONArray(TAG_ITEMS);
//This is the solution that I want to optimize
urls = new String[items.length()];
// looping through All items
for(int i = 0; i < items.length(); i++){
JSONObject c = items.getJSONObject(i);
// Storing each json item in variable
String title = c.getString(TAG_TITLE);
String description = c.getString(TAG_DESCRIPTION);
String author = c.getString(TAG_AUTHOR);
// Media is another JSONObject
JSONObject m = c.getJSONObject(TAG_MEDIA);
String url = m.getString(TAG_URL);
// creating new HashMap
HashMap<String, String> map = new HashMap<String, String>();
// adding each child node to HashMap key => value
map.put(TAG_TITLE, title);
map.put(TAG_DESCRIPTION, description);
map.put(TAG_AUTHOR, author);
map.put(TAG_URL, url);
// Solution
urls[i] = url;
// adding HashList to ArrayList
itemsList.add(map);
}
} catch (JSONException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}