【Map】MapTest,mapmaptest

來源:互聯網
上載者:User

【Map】MapTest,mapmaptest

 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 }

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.