java - Change type of for loop to forEach? -
this question has answer here:
- foreach jsonarray , jsonobject 3 answers
i have created jsonarray "listsofemployee"
, put lot of data in it.
i have loop:
for (int = 0; < listofemployee.length(); i++)
i use variable int = 0
example in way:
jsonobject currentemploye = listofemployee.getjsonobject(i);
can convert loop foreach current item/employee? possible?
yes. possible, can try when use java 7 or lower
for(object obj: listofemployee){ if (obj instanceof jsonobject ) { parse((jsonobject) obj); } }
and java 8 array.foreach(item -> { jsonobject obj = (jsonobject) item; parse(obj); });
Comments
Post a Comment