Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package javaapplication25;
- import java.util.ArrayList;
- import java.util.Hashtable;
- import java.util.Iterator;
- public class JavaApplication25 {
- public static void main(String[] args) {
- // Arraylist
- ArrayList<String> al=new ArrayList<String>();
- al.add("Ravi");
- al.add("Vijay");
- al.add("Ravi");
- al.add("Ajay");
- Iterator itr=al.iterator();
- while(itr.hasNext()){
- System.out.println(itr.next());
- }
- // Hashtable
- Hashtable<String,String> urutan = new Hashtable<String,String>();
- urutan.put("A1", "Nasi Goreng");
- urutan.put("A2","Mie Ayam");
- urutan.put("A3","Es Teler");
- urutan.put("A4", "Es Teh");
- urutan.put("A5","Es Campur");
- urutan.put("A6","Lalapan");
- urutan.put("A7", "Tahu Campur");
- urutan.put("A8","Nasi Pecel");
- urutan.put("A9","Soto Ayam");
- urutan.put("A10","Soto Daging");
- String str;
- for(int i=1;i<11;i++) {
- str = "A" + i;
- if(isganjil(str)) {
- System.out.println(str + " : " + urutan.get(str));;
- }
- }
- System.out.println("Value of key 'A4': "+urutan.get("A4"));
- System.out.println("Is Hashtable empty? "+urutan.isEmpty());
- urutan.remove("A3");
- urutan.remove("A5");
- System.out.println(urutan);
- System.out.println("Size of the Hashtable:"+urutan.size());
- }
- public static boolean isganjil(String a) {
- String b = a;
- b = b.replaceAll("[^0-9]", "");
- return Integer.parseInt(b) % 2 != 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement