• 暑假日报-30


    今天练习了数据结构,明天看包

    import java.util.Vector;

    import java.util.Enumeration;

    public class EnumerationTester {

    public static void main(String args[]) {

    Enumeration<String> days;

    Vector<String> dayNames = new Vector<String>();

    dayNames.add("Sunday");

    dayNames.add("Monday");

    dayNames.add("Tuesday");

    dayNames.add("Wednesday");

    dayNames.add("Thursday");

    dayNames.add("Friday");

    dayNames.add("Saturday");

    days = dayNames.elements();

    while (days.hasMoreElements()){

    System.out.println(days.nextElement());

    }

    }

    }

    import java.util.*;
    
    public class VectorDemo {
    
       public static void main(String args[]) {
          // initial size is 3, increment is 2
          Vector v = new Vector(3, 2);
          System.out.println("Initial size: " + v.size());
          System.out.println("Initial capacity: " +
          v.capacity());
          v.addElement(new Integer(1));
          v.addElement(new Integer(2));
          v.addElement(new Integer(3));
          v.addElement(new Integer(4));
          System.out.println("Capacity after four additions: " +
              v.capacity());
    
          v.addElement(new Double(5.45));
          System.out.println("Current capacity: " +
          v.capacity());
          v.addElement(new Double(6.08));
          v.addElement(new Integer(7));
          System.out.println("Current capacity: " +
          v.capacity());
          v.addElement(new Float(9.4));
          v.addElement(new Integer(10));
          System.out.println("Current capacity: " +
          v.capacity());
          v.addElement(new Integer(11));
          v.addElement(new Integer(12));
          System.out.println("First element: " +
             (Integer)v.firstElement());
          System.out.println("Last element: " +
             (Integer)v.lastElement());
          if(v.contains(new Integer(3)))
             System.out.println("Vector contains 3.");
          // enumerate the elements in the vector.
          Enumeration vEnum = v.elements();
          System.out.println("
    Elements in vector:");
          while(vEnum.hasMoreElements())
             System.out.print(vEnum.nextElement() + " ");
          System.out.println();
       }
    }
    import java.util.*;
    
    public class HashTableDemo {
    
       public static void main(String args[]) {
          // Create a hash map
          Hashtable balance = new Hashtable();
          Enumeration names;
          String str;
          double bal;
    
          balance.put("Zara", new Double(3434.34));
          balance.put("Mahnaz", new Double(123.22));
          balance.put("Ayan", new Double(1378.00));
          balance.put("Daisy", new Double(99.22));
          balance.put("Qadir", new Double(-19.08));
    
          // Show all balances in hash table.
          names = balance.keys();
          while(names.hasMoreElements()) {
             str = (String) names.nextElement();
             System.out.println(str + ": " +
             balance.get(str));
          }
          System.out.println();
          // Deposit 1,000 into Zara's account
          bal = ((Double)balance.get("Zara")).doubleValue();
          balance.put("Zara", new Double(bal+1000));
          System.out.println("Zara's new balance: " +
          balance.get("Zara"));
       }
    }
     
  • 相关阅读:
    springboot(eureka子项目)+idea+jsp 404问题
    什么是区块链以及他的6个特征?
    elasticsearch启动时提示内存不足错误的解决方法
    ElasticSearch 安装root用户启动失败问题解决
    防抖节流(立即执行和延时执行)
    将数字转为千分制格式(最简单)
    微信H5跳转任意小程序
    原生html+css设置项目主题色(超简单)
    H5获取手机型号
    css属性——env()和constant()设置安全区域
  • 原文地址:https://www.cnblogs.com/L-L-ALICE/p/13449621.html
Copyright © 2020-2023  润新知