+ 1

Can somebody help me understand the following code?

public static ArrayList<Words> extractData(String requestUrl) { URL url = createUrl(requestUrl); //1 jsonResponse = makeHttpRequest(url); //2 ArrayList<Words> jsonData = extractJSON(jsonResponse); //3 return jsonData; //4 } public static ArrayList<Words> extractJSON(String JSON_String){ ArrayList<Words> words = new ArrayList<Words>(); //some code return words; } i understand //1 converting string to URL //2 making http request and storing the data in jsonResponse What does //3 //4 mean?

24th May 2019, 7:48 AM
Ghost rider
1 Réponse
+ 2
it converts (parse) data from String jsonResponse to ArrayList<Words> and return data in ArrayList instead in String ArrayList<Words> is like array of Objects, you can imagine it like as Object[] jsonData = new Object[size]; here are stored objects of type Words, Words is some class, so it is like Words[] jsonData = new Words[size]; More precisely ArrayList is resizable ordered collection (group of objects) from Collections framework. It is a 'generic class' and stores objects of generic type that is unknown in advance and is determined by a 'diamond' syntax <Type> when this array is declared by programmer. Here it is type <Words>. https://www.sololearn.com/learn/Java/2179/?ref=app https://docs.oracle.com/javase/tutorial/java/generics/types.html https://docs.oracle.com/javase/8/docs/api/java/util/ArrayList.html
25th May 2019, 1:13 AM
zemiak