Scan and perform action 5 times | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Scan and perform action 5 times

Hi, I have an array with 5 elements String[] names= {"vin","gold","bop","test","face"}; Now I want to check the array element from 0 to 4 against a list. It could be an array list or linked list. Example: LinkedList<String> linkedlist= new LinkedList<String>(); linkedlist.add("gold"); linkedlist.add("test"); linkedlist.add("vin"); linkedlist.add("fsce"); linkedlist.add("test"); linkedlist.add("become"); So now I want to use a while loop to check each array element one by one from 0 to 4. If element from index 0 matches I want to use the if statement and perform an action. Then the while loop go back again and check index 1, do the same thing until the last element on index 4. How do I do that?

19th May 2019, 3:51 PM
Sibusiso Mbambo
2 Answers
+ 2
Emmanuel Mbambo https://www.sololearn.com/Discuss/1806947/?ref=app I don't see a real difference between this and your last question.
19th May 2019, 5:09 PM
Denise Roßberg
Denise Roßberg - avatar
0
Each element is important because I need to perform the action 5 times(0 to 4) checking each element from 0 to 4. I don't know if "next" method is of use.
19th May 2019, 4:07 PM
Sibusiso Mbambo