6 Cách Duyệt Mảng Trong Java

Skip to content

public class Unit1 {

public static void main(String[] args) { ArrayList<String> list = new ArrayList<>(); list.add("A1"); list.add("A2"); list.add("A3"); list.add("A4"); list.remove(0);

// Cách 1

for (int i = 0; i < list.size(); i++) { System.out.println(list.get(i)); } System.out.println("=======================================");

// Cách 2

for (String array : list) { System.out.println(array); } System.out.println("=======================================");

// Cách 3

list.forEach((item) -> { System.out.println(item); }); System.out.println("=======================================");

// Cách 4

Iterator iterator = list.iterator(); while (iterator.hasNext()) { String string = (String) iterator.next(); System.out.println(string); } System.out.println("=======================================");

// Cách 5

list.stream().forEach(System.out::println); System.out.println("=======================================");

// Cách 6

list.parallelStream().forEach(System.out::println); }

}

共有:

  • Twitter
  • Facebook

Related

Post navigation

Previous Post Hướng dẫn sử dụng biểu thức chính quy trong JavaNext Post SwapList thay đổi vị trị trong mảng Privacy & Cookies: This site uses cookies. By continuing to use this website, you agree to their use. To find out more, including how to control cookies, see here: Cookie Policy
  • Subscribe Subscribed
    • chungit.home.blog
    • Sign me up
    • Already have a WordPress.com account? Log in now.
    • chungit.home.blog
    • Customize
    • Subscribe Subscribed
    • Sign up
    • Log in
    • Copy shortlink
    • Report this content
    • View post in Reader
    • Manage subscriptions
    • Collapse this bar
Design a site like this with WordPress.comGet started

Từ khóa » Duyệt List Trong Java