tailieunhanh - Bài giảng Cấu trúc dữ liệu: Chương 4 - Nguyễn Xuân Vinh

Bài giảng Cấu trúc dữ liệu - Chương 4: Iterator - Comparable - Comparator trình bày về java conllection architecture, examining sets and maps, iterator methods, iterator example, comparable, comparator,.Mời bạn đọc cùng tham khảo. | Iterator - Comparable - Comparator Nguyễn Xuân Vinh nguyenxuanvinh@ CẤU TRÚC DỮ LIỆU DATA STRUCTURES [214331] Java Collection Architecture The Differences!!! How to browse element? Elements of List are indexed. int value = list[0]; Elements of LinkedList, Sets and Maps can't be accessed by index How to remove element? index 0 1 2 3 4 5 6 7 8 9 value 3 8 9 7 5 12 0 0 0 0 List Set "the" "to" "from" "we" Linked List Map Examining sets and maps elements of Java Sets and Maps can't be accessed by index must use a "foreach" loop: Set scores = new HashSet(); for (int score : scores) { ("The score is " + score); } Problem: foreach is read-only; cannot modify set while looping for (int score : scores) { if (score scores = new HashSet(); for (int score : scores) { ("The score is " + score); } Problem: foreach is read-only; cannot modify set while looping for (int score : scores) { if (score set = new HashSet(); . Iterator itr = (); . hasNext() returns true if there are more elements to examine next() returns the next element from the collection (throws a NoSuchElementException if there are none left to examine) remove() removes from the collection the last value returned by next() (throws IllegalStateException if you have not called next() yet) Iterator example Set scores = new .

TỪ KHÓA LIÊN QUAN
crossorigin="anonymous">
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.