L10.5: ArrayList For Each Example

PHOTO EMBED

Wed Oct 18 2023 13:34:00 GMT+0000 (Coordinated Universal Time)

Saved by @testpro #java

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class Main {
    public static void main(String[] args) {

        List<String> koelPages = new ArrayList<>();

        koelPages.add("LoginPage");
        koelPages.set(0, "RegistrationPage");
        koelPages.add("HomePage");
        koelPages.add("ProfilePage");
        koelPages.add("APage");
        koelPages.add("ZPage");
        Collections.sort(koelPages);
        Collections.reverse(koelPages);

        for (String i : koelPages) {
            System.out.println(i);
        }
    }
}
/* Output:
ZPage
RegistrationPage
ProfilePage
HomePage
APage
*/
content_copyCOPY