Created
August 5, 2016 04:00
-
-
Save dimMaryanto93/e1412b48ea8eb1512c9d2beb94324c1a to your computer and use it in GitHub Desktop.
Elements collection di Java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class BelajarList{ | |
public static void main(String[] args){ | |
java.util.List<String> daftarEmails = new java.util.ArrayList<String>(); | |
daftarEmails.add("[email protected]"); | |
System.out.println("Email pertama: "+daftarEmails.get(0)); | |
daftarEmails.set(0, "[email protected]"); | |
System.out.println("Email setelah diset: "+daftarEmails.get(0)); | |
daftarEmails.remove(0); | |
System.out.println("Jumlah email: "+ daftarEmails.size()); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class BelajarMap{ | |
public static void main(String[] args){ | |
java.util.Map<String, String> daftarBarang = new java.util.HashMap<String,String>(); | |
daftarBarang.put("001", "Product 001") | |
daftarBarang.put("P102", "Product 002"); | |
System.out.println("Nilai 001 adalah "+ daftarBarang.get("001")); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class BelajarSet{ | |
public static void main(String[] args){ | |
java.util.Set<String> daftarEmails = new java.util.HashSet<String>(); | |
daftarEmails.add("[email protected]"); | |
System.out.println("Jumlah email setalah add ke 1: "+ daftarEmails.size()); | |
daftarEmails.add("[email protected]"); | |
System.out.println("Jumlah email setelah add ke 2: "+ daftarEmails.size()); | |
daftarEmails.add("[email protected]"); | |
System.out.println("Jumlah email setelah add ke 3: "+ daftarEmails.size()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment