1. Trang chủ
  2. » Thể loại khác

java linkedhashset class

2 131 0

Đang tải... (xem toàn văn)

THÔNG TIN TÀI LIỆU

Cấu trúc

  • Lớp LinkedHashSet trong Java

    • Ví dụ

Nội dung

http://vietjack.com/java/index.jsp Copyright © vietjack.com Lớp LinkedHashSet Java Lớp LinkedHashSet Java kế thừa HashSet Lớp LinkedHashSet trì linked list entry Set, theo thứ tự chúng chèn Điều cho phép tính lặp lại theo thứ tự chèn qua Set Đó là, tuần hoàn qua LinkedHashSet sử dụng Iterator, phần tử trả theo thứ tự chúng chèn Hash code sau sử dụng index, liệu mà liên kết với key lưu trữ Phép biến đổi key vào hash code thực tự động Để hiểu sâu khái niệm trình bày chương này, mời bạn tham khảo loạt bài: Ví dụ Collection Java Lớp LinkedHashSet hỗ trợ constructor Mẫu constructor xây dựng hash set mặc định LinkedHashSet( ) Mẫu Constructor thứ hai khởi tạo hash set sử dụng phần tử c LinkedHashSet(Collection c) Constructor khởi tạo dung lượng hash set capacity Dung lượng tăng tự động phần tử thêm vào tới Hash LinkedHashSet(int capacity) Mẫu Constructor thứ tư khởi tạo dung lượng fill ratio (cũng gọi dung lượng tải) hash set từ tham số LinkedHashSet(int capacity, float fillRatio) Ví dụ Chương trình sau minh họa phương thức hỗ trợ lớp LinkedHashSet Java: import java.util.*; http://vietjack.com/ Trang chia sẻ học online miễn phí Page http://vietjack.com/java/index.jsp Copyright © vietjack.com public class HashSetDemo { public static void main(String args[]) { // create a hash set LinkedHashSet hs = new LinkedHashSet(); // add elements to the hash set hs.add("B"); hs.add("A"); hs.add("D"); hs.add("E"); hs.add("C"); hs.add("F"); System.out.println(hs); } } Nó cho kết sau: [B, A, D, E, C http://vietjack.com/ Trang chia sẻ học online miễn phí Page ...http://vietjack.com /java/ index.jsp Copyright © vietjack.com public class HashSetDemo { public static void main(String args[]) { // create a hash set LinkedHashSet hs = new LinkedHashSet( ); //

Ngày đăng: 03/12/2017, 00:04

TỪ KHÓA LIÊN QUAN

w