Java tutorial
//package com.java2s; //License from project: Open Source License import java.util.ArrayList; import java.util.HashMap; import java.util.List; public class Main { public static Object asListItem(Object node, String key, int idx) { List<?> list = asList(node, key); return (idx >= 0 && idx < list.size() ? list.get(idx) : null); } public static List<?> asList(Object node) { if (node instanceof List<?>) { return (List<?>) node; } else { return new ArrayList<Object>(); } } public static List<?> asList(Object node, String key) { Object value; if ((node instanceof HashMap<?, ?>) && ((value = ((HashMap<?, ?>) node).get(key)) != null)) { if (value instanceof List<?>) { return (List<?>) value; } else { return new ArrayList<Object>(); } } else { return new ArrayList<Object>(); } } }