标签:
javaweb_Ⅰjava基础增强——断点
@Test//必须添加,通知程序使JUnit public void testRun () { Person p = new Person(); p .run (); }
javaweb_Ⅳjava基础增强——增强for循环
@Test public void test1() { int arr[] = { 1, 2, 3 }; for (int num : arr) { System.out.println(num); } } @Test public void test2() { List list = new ArrayList<>(); list.add(1); list.add(2); list.add(3); for (Object object : list) { int i = (Integer) object; System.out.println(i); } } @Test public void test3() { Map map = new LinkedHashMap(); map.put("1", "aaa"); map.put("2", "aba"); map.put("3", "aac"); // 第一种方式 for (Object object : map.keySet()) { String key = (String) object; String value = (String) map.get(key); System.out.println(key + "=" + value); } //第二种方式 for (Object object : map.entrySet()) { Map.Entry entry = (Entry) object; String key = (String) entry.getKey(); String value = (String) entry.getValue(); System.out.println(key + "=" + value); } } /* * HashMap()通过hashmap的算法实现 传统map数据的取出方式 * 1 * Set set = map.keySet(); * Iterator it = set.iterator(); * while(it.hasNext()){ * String key = (String)it.next(); * String value = (String)map.get(key); * sys; * } * * 2 * * Set set = map.entrySet(); * Iterator it = set.iterator(); * while(it.hasNext()){ * Map.Entry entry = (Entry)it.next(); * String key =(String)entry.getKey(); * String value = (String)entry.getValue(); * sys; * } */
enum Grade{ //class A,B,C,D,E; //object } @Test public void testGrade () { System. out. println( Grade. A. getNum()); } @Test public void testChinaNum () { System. out. println( China. A. getNum()); System. out. println( China. B. chinaNum()); } //如何定义枚举的构造函数/方法和字段/去封装更多的信息。 enum Grade { A ("100-90" ), B ("100-0090" ), C ("100-090" ), D ("100-900" ), E( "1000-90"); private String value ; private Grade( String value ) { this .value = value; }//私有构造函数,不允许随便增加枚举对象 public String getNum() { return this .value ; }//对外提供获得枚举对象的信息 } // 带抽象方法的枚举 enum China { A ("100-90" ) { public String chinaNum() { return "优" ;//每一个枚举对象需要实现抽象方法 }; }, B ("100-0090" ) { public String chinaNum() { return "优" ; }; }, C ("100-090" ) { public String chinaNum() { return "优" ; }; }, D ("100-900" ) { public String chinaNum() { return "优" ; }; }, E ("1000-90" ) { public String chinaNum() { return "优" ; }; }; private String value; private China( String value ) { this .value = value; } public String getNum() { return this .value ; } public abstract String chinaNum();//抽象方法 }
标签:
原文地址:http://www.cnblogs.com/night-tian/p/4328400.html