peri hoki perihoki clarustologistics rimashaop.com pola taktis menang gates of olympus x1000 perihoki pemain perihoki bongkar trik jepep starlight princess x1000 perihoki beri panduan lengkap bermain mahjong ways 2 pgsoft tips cara penghasil uang pgsoft mahjong ways 2 perihoki mahjong wins 3 perihoki memberikan penggali terbesar fenomena gates of olympus buka peluang besar bagi duta76 cara dapat pola emas rahasia di duta7 wild west gold trik menang pgsoft mahjong ways 2 modal receh maxwin duta76 duta76 main pgsoft mahjong ways 2 di sela istirahat scatter hitam mahjong wins 3 spin pasti jepe duta76 perihoki spin mahjong ways 2 pgsoft scatter hitam maxwin simbol mahjong wins 3 yang sering muncul di awal perihoki trik gampang menang mahjong wins cuan mahjong wins 3 tanpa henti pola spin taruhan kecil mahjong wins strategi kunci scatter hitam beruntun gacor total mahjong ways kemenangan maksimal mahjong ways kemenangan pria pekanbaru mahjong ways mahjong wins3 fenomena baru sumatera barat menangkan mahjong dengan lincah menembus batas keberuntungan mahjong ways menjajal keberuntungan di mahjong ways pola gratis mahjong ways1 scatter hitam senjata rahasia mahjong wins teknik spinning menguntungkan untuk scatter hitam analisis rtp tertinggi mahjong wins fenomena scatter hitam mahjong wins ibu rumah tangga dan keberuntungan mahjong keseruan main mahjong wins3 menang mahjong pengguna baru di sosial media menghargai setiap momen di mahjong ways serunya main mahjong di warung internet spin slow motion mancing scatter strategi jitu maxwin mahjong ways strategi jitu menang mahjong modal kecil jackpot besar anak kampung papua menggemparkan mahjong keajaiban scatter hitam mahjong ways keberhasilan joni mahjong wins kejaiban mahjong ways di ujung jalan ketua mahjong wins3 kehadiran kemenangan dimulai dari bali mahjong kehadiran yang menguntungkan mahjong menggila adat88 panduan kilat raih 108 juta tips memenangkan mahjong barista kopi menang 110 juta spin mahjong dakota76 scatter hitam mahjong wins 3 gagal cpns menang mahjong wins 3 rp120 juta kisah karyawan minimarket dapat thr lebih awal mahjong wins kisah pelajar sma kuasai mahjong wins 3 inspirasi sekolah kisah penjaga parkir tanah abang motor baru mahjong wins kisah sukses ibu rumah tangga bandung mahjong wins mahasiswa kkn beli iphone15 mahjong wins3 dakota mantan anak band influencer mahjong scatter hitam pola rtp senin gates of olympus guru matematika tukang cuci motor menemukan keberuntungan di mahjong
A PHP Error was encountered
Severity: Warning
Message: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time
Filename: Session/Session.php
Line Number: 282
Backtrace:
File: /home/blogchuabenh/domains/freetuts.net/public_html/site/controllers/Main_controller.php
Line: 10
Function: __construct
File: /home/blogchuabenh/domains/freetuts.net/public_html/sources/index.php
Line: 299
Function: require_once
File: /home/blogchuabenh/domains/freetuts.net/public_html/index.php
Line: 26
Function: require_once
A PHP Error was encountered
Severity: Warning
Message: session_set_cookie_params(): Cannot change session cookie parameters when headers already sent
Filename: Session/Session.php
Line Number: 294
Backtrace:
File: /home/blogchuabenh/domains/freetuts.net/public_html/site/controllers/Main_controller.php
Line: 10
Function: __construct
File: /home/blogchuabenh/domains/freetuts.net/public_html/sources/index.php
Line: 299
Function: require_once
File: /home/blogchuabenh/domains/freetuts.net/public_html/index.php
Line: 26
Function: require_once
A PHP Error was encountered
Severity: Warning
Message: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time
Filename: Session/Session.php
Line Number: 304
Backtrace:
File: /home/blogchuabenh/domains/freetuts.net/public_html/site/controllers/Main_controller.php
Line: 10
Function: __construct
File: /home/blogchuabenh/domains/freetuts.net/public_html/sources/index.php
Line: 299
Function: require_once
File: /home/blogchuabenh/domains/freetuts.net/public_html/index.php
Line: 26
Function: require_once
A PHP Error was encountered
Severity: Warning
Message: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time
Filename: Session/Session.php
Line Number: 314
Backtrace:
File: /home/blogchuabenh/domains/freetuts.net/public_html/site/controllers/Main_controller.php
Line: 10
Function: __construct
File: /home/blogchuabenh/domains/freetuts.net/public_html/sources/index.php
Line: 299
Function: require_once
File: /home/blogchuabenh/domains/freetuts.net/public_html/index.php
Line: 26
Function: require_once
A PHP Error was encountered
Severity: Warning
Message: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time
Filename: Session/Session.php
Line Number: 315
Backtrace:
File: /home/blogchuabenh/domains/freetuts.net/public_html/site/controllers/Main_controller.php
Line: 10
Function: __construct
File: /home/blogchuabenh/domains/freetuts.net/public_html/sources/index.php
Line: 299
Function: require_once
File: /home/blogchuabenh/domains/freetuts.net/public_html/index.php
Line: 26
Function: require_once
A PHP Error was encountered
Severity: Warning
Message: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time
Filename: Session/Session.php
Line Number: 316
Backtrace:
File: /home/blogchuabenh/domains/freetuts.net/public_html/site/controllers/Main_controller.php
Line: 10
Function: __construct
File: /home/blogchuabenh/domains/freetuts.net/public_html/sources/index.php
Line: 299
Function: require_once
File: /home/blogchuabenh/domains/freetuts.net/public_html/index.php
Line: 26
Function: require_once
A PHP Error was encountered
Severity: Warning
Message: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time
Filename: Session/Session.php
Line Number: 317
Backtrace:
File: /home/blogchuabenh/domains/freetuts.net/public_html/site/controllers/Main_controller.php
Line: 10
Function: __construct
File: /home/blogchuabenh/domains/freetuts.net/public_html/sources/index.php
Line: 299
Function: require_once
File: /home/blogchuabenh/domains/freetuts.net/public_html/index.php
Line: 26
Function: require_once
A PHP Error was encountered
Severity: Warning
Message: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time
Filename: Session/Session.php
Line Number: 375
Backtrace:
File: /home/blogchuabenh/domains/freetuts.net/public_html/site/controllers/Main_controller.php
Line: 10
Function: __construct
File: /home/blogchuabenh/domains/freetuts.net/public_html/sources/index.php
Line: 299
Function: require_once
File: /home/blogchuabenh/domains/freetuts.net/public_html/index.php
Line: 26
Function: require_once
A PHP Error was encountered
Severity: Warning
Message: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time
Filename: drivers/Session_files_driver.php
Line Number: 108
Backtrace:
File: /home/blogchuabenh/domains/freetuts.net/public_html/site/controllers/Main_controller.php
Line: 10
Function: __construct
File: /home/blogchuabenh/domains/freetuts.net/public_html/sources/index.php
Line: 299
Function: require_once
File: /home/blogchuabenh/domains/freetuts.net/public_html/index.php
Line: 26
Function: require_once
A PHP Error was encountered
Severity: Warning
Message: session_set_save_handler(): Cannot change save handler when headers already sent
Filename: Session/Session.php
Line Number: 110
Backtrace:
File: /home/blogchuabenh/domains/freetuts.net/public_html/site/controllers/Main_controller.php
Line: 10
Function: __construct
File: /home/blogchuabenh/domains/freetuts.net/public_html/sources/index.php
Line: 299
Function: require_once
File: /home/blogchuabenh/domains/freetuts.net/public_html/index.php
Line: 26
Function: require_once
A PHP Error was encountered
Severity: Warning
Message: session_start(): Cannot start session when headers already sent
Filename: Session/Session.php
Line Number: 143
Backtrace:
File: /home/blogchuabenh/domains/freetuts.net/public_html/site/controllers/Main_controller.php
Line: 10
Function: __construct
File: /home/blogchuabenh/domains/freetuts.net/public_html/sources/index.php
Line: 299
Function: require_once
File: /home/blogchuabenh/domains/freetuts.net/public_html/index.php
Line: 26
Function: require_once
Phương thức forEach() trong HashMap Java - Freetuts
CÁC HÀM JAVA
CÁC CHỦ ĐỀ
BÀI MỚI NHẤT
Phương thức forEach() trong HashMap Java
Trong bài viết này chúng ta sẽ tìm hiểu về phương thức forEach() trong HashMap Java. Đây là một phương thức được sử dụng để thực hiện một hành động lên tất cả các cá thể trong hashmap và làm thay đổi chúng.
Bài viết này được đăng tại freetuts.net , không được copy dưới mọi hình thức.
Phương thức forEach() là phương thức có sẵn trong thư viện HashMap, vì vậy để sử dụng được nó các bạn cần import thư viện đã nhé: import java.util.HashMap;
Cú pháp phương thức forEach() trong HashMap Java
Trước tiên chúng ta sẽ tìm hiểu về cú pháp của nó đã nhé.
hashmap.forEach(BiConsumer<K, V> action)
Trong đó:
Bài viết này được đăng tại [free tuts .net]
hashmap là một đối tượng của lớp HashMap.
action - các hành động được thực hiện trên mỗi cá thể của hashmap.
Phương thức forEach() không trả về bất kỳ giá trị nào. Thay vào đó nó sẽ làm thay đổi tất cả các cá thể trong hashmap.
Ví dụ: chúng ta có một hashmap : {Java=1", "C=2", "Python=3}. Bây giờ sử dụng phương thức forEach() để bình phương value của tất cả các cá thể trong hashmap.
hashmap.forEach((key, value) -> {
value = value * value;
System.out.print(key + "=" + value + " ");
});
Như vậy sau khi chạy chương trình thì hashmap : {Java=1", "C=4", "Python=9}.
Cách dùng phương thức forEach() trong HashMap Java
Trong phần này mình sẽ thực hiện một ví dụ sử dụng phương thức forEach() để minh họa cho cách dùng của nó.
Cụ thể mình sẽ khai báo một hashmap rồi khởi tạo cho nó một số cá thể nhất điịnh. Sau đó sử dụng phương thức forEach() để tính value sau khi giảm 10% và hiển thị ra value mới.
import java.util.HashMap;
class Main {
public static void main(String[] args) {
//khai báo một hashmap tên prices
HashMap<String, Integer> prices = new HashMap<>();
//sử dụng phương thức put() để thêm các cá thể cho prices
prices.put("Shoes", 200);
prices.put("Bag", 300);
prices.put("Pant", 150);
System.out.println("\n\nGiá ban đầu của các sản phẩm: " + prices);
System.out.print("Giá sau khi giảm giá 10%: ");
// tính 10% value của các cá thể rồi cộng với value ban đầu
prices.forEach((key, value) -> {
value = value - value * 10/100;
System.out.print(key + "=" + value + " ");
});
System.out.println("\n---------------------------------");
System.out.println("Chương trình này được đăng tại Freetuts.net");
}
}
Kết quả:
Như vậy là chúng ta đã tìm hiểu xong phương thức forEach() trong HashMap Java. Ở các bài tiếp theo mình sẽ tiếp tục giới thiệu các phương thức khác trong HashMap, các bạn chú ý theo dõi nhé !!!
Câu hỏi thường gặp liên quan:
Cùng chuyên mục: