java - Change type of for loop to forEach? -


this question has answer here:

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

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -