Created
April 7, 2016 22:56
-
-
Save rastaman/c388707b834e66ba2e6709d8b67a91f1 to your computer and use it in GitHub Desktop.
Why no Iterable JSON Array in org.json ?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.util.ArrayList; | |
| import java.util.Iterator; | |
| import java.util.List; | |
| import org.json.JSONArray; | |
| public class IterableJSONArray<T> extends JSONArray implements Iterable<T> { | |
| @SuppressWarnings("unchecked") | |
| @Override | |
| public Iterator<T> iterator() { | |
| List<T> result = new ArrayList<T>(); | |
| for (int i = 0; i < this.length(); i++) { | |
| result.add((T) this.get(i)); | |
| } | |
| return result.iterator(); | |
| } | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note : there is much more efficient ways to write the iterable method, it is just an example/POC.