zoukankan      html  css  js  c++  java
  • 【Map】MapTest

     1 package cn.itcast.p1.map.test;
     2 
     3 import java.util.HashMap;
     4 import java.util.Map;
     5 
     6 public class MapTest2 {
     7 
     8     public static void main(String[] args) {
     9         /*
    10          * Map在有映射关系时,可以优先考虑。
    11          * 
    12          * 在查表法中的应用较为多见。
    13          */
    14         String week = getWeek(1);
    15         
    16         System.out.println(week);
    17         
    18         System.out.println(getWeekByMap(week));
    19 
    20     }
    21 
    22     public static String getWeekByMap(String week) {
    23         Map<String,String> map = new HashMap<String,String>();
    24         
    25         map.put("星期一", "Mon");
    26         map.put("星期二", "Tus");
    27         map.put("星期三", "Wes");
    28         map.put("星期日", "Sun");
    29         
    30         
    31         return map.get(week);
    32     }
    33 
    34     public static String getWeek(int i) {
    35         if (i<1 || i>7)
    36             throw new RuntimeException("没有对应的星期");
    37         
    38         String[] weeks = {"","星期一","星期二","星期三","星期四"};
    39         
    40         return weeks[i];
    41     }
    42 
    43 }
  • 相关阅读:
    lnmp 优化
    linux-lnmp 搭建报错
    nfs 配置
    全网备份脚本rsync
    .Net面试题二
    软件设计模式
    .Net面试题一
    asp.net运行机制
    NHiberante的优缺点
    什么是架构、框架、模式和平台
  • 原文地址:https://www.cnblogs.com/Newbie-Cai/p/5814262.html
Copyright © 2011-2022 走看看