Method A (conventional method):
- We get JsonArray from an API
- Iterate that JsonArray (inside for loop) and Pass values from JsonArray to an object of Model class (Getter and Setter) and add that object of the model class to an ArrayList
- Pass that ArrayList to recyclerAdapter
- Iterate that ArrayList inside the onBindViewHolder method of recyclerAdapter
- and set values to textView, imageView etc inside the onBindViewHolder method
Method B:
- We get JsonArray from an API
- Pass the whole JsonArray to recyclerAdapter
Iterate jsonArray inside onBindViewHolder (without using ArrayList) and setValues directly to textViews, imageViews etc as shown below
@Override public void onBindViewHolder(Holder holder, int i) { try { holder.textView.setText(jsonArray.getJSONObject(i).getString("textKey")); } catch (JSONException e) { e.printStackTrace(); } }
Will, there be any performance improvement while I use the second method as we are not using model class and ArrayList.
Will the performance decrease or remain same.
I don't care about readability, my only concern here is performance.
Note:- using try catch multiple times has no effect on performance so we can ignore that.