Skip to content

Instantly share code, notes, and snippets.

@dimMaryanto93
Created August 5, 2016 04:00
Show Gist options
  • Save dimMaryanto93/e1412b48ea8eb1512c9d2beb94324c1a to your computer and use it in GitHub Desktop.
Save dimMaryanto93/e1412b48ea8eb1512c9d2beb94324c1a to your computer and use it in GitHub Desktop.
Elements collection di Java
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());
}
}
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"));
}
}
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