1 2 3 4 | [AppleScript] 纯文本查看 复制代码 void add(int index,E element) |
1 2 3 4 5 6 7 | void addFirst(E e) void addLast(E e) E getFirst(E e) E getLast(E e) E removeFirst() E Pop() void push(E e) |
01 02 03 04 05 06 07 08 09 10 11 12 13 | public static void main(String[] args) { int sum2 = getSum(6, 7, 2, 12, 2121); System.out.println(sum2); } //可变参数写法 public static int getSum(int... arr) { int sum = 0; for (int a : arr) { sum += a; } return sum; } } |
1 2 3 4 5 | public V put(K key, V value) : 把指定的键与指定的值添加到Map集合中。 public V remove(Object key) : 把指定的键所对应的键值对元素 在Map集合中删除,返回被删除元素的值。 public V get(Object key) 根据指定的键,在Map集合中获取对应的值。 public Set<K> keySet() : 获取Map集合中所有的键,存储到Set集合中。 public Set<Map.Entry<K,V>> entrySet() : 获取到Map集合中所有的键值对对象的集合(Set集合)。 |
01 02 03 04 05 06 07 08 09 10 11 12 13 | public class MapDemo { public static void main(String[] args) { HashMap<String, String> map = new HashMap<String, String>(); map.put("黄晓明", "杨颖"); map.put("文章", "马伊琍"); map.put("邓超", "孙俪"); System.out.println(map); System.out.println(map.remove("邓超")); System.out.println(map); System.out.println(map.get("黄晓明")); System.out.println(map.get("邓超")); } } |
[AppleScript] 纯文本查看 复制代码 public class MapDemo01 { |
public class MapDemo02 {
public static void main(String[] args) {
HashMap<String, String> map = new HashMap<String,String>();
map.put("胡歌", "霍建华");
map.put("郭德纲", "于谦");
map.put("薛之谦", "大张伟");
Set<Entry<String,String>> entrySet = map.entrySet();
for (Entry<String, String> entry : entrySet) {
String key = entry.getKey();
String value = entry.getValue();
System.out.println(key+"的CP是:"+value);
}
}
}
01 02 03 04 05 06 07 08 09 10 11 12 | public class LinkedHashMapDemo { public static void main(String[] args) { LinkedHashMap<String, String> map = new LinkedHashMap<String, String>(); map.put("邓超", "孙俪"); map.put("李晨", "范冰冰"); map.put("刘德华", "朱丽倩"); Set<Entry<String, String>> entrySet = map.entrySet(); for (Entry<String, String> entry : entrySet) { System.out.println(entry.getKey() + " " + entry.getValue()); } } } |
1 2 3 4 5 6 7 8 9 | public class HelloJDK9 { public static void main(String[] args) { Set<String> str1=Set.of("a","b","c"); System.out.println(str1); Map<String,Integer> str2=Map.of("a",1,"b",2); System.out.println(str2); List<String> str3=List.of("a","b"); System.out.println(str3); } |
1 2 3 4 | static <T> boolean addAll(Collection<T> c,T...elements) static void shuffle(List<?> list) static <T> void sort(List<T> list): 实现Comparable<E>接口,重写int CompareTo(T e)方法 static <T> void sort(List<T> list,Comparator<?super T>):比较器排序 |
1 2 3 4 5 6 7 | Collections.sort(list, new Comparator<Person>() { @Override public int compare(Person o1, Person o2) { // o1 - o2: 升序 // o2 - o1: 降序 return o1.getAge() - o2.getAge(); } }); |
1 2 3 | String getmessage();返回此throwble 的简短描述 String tostring();返回此throwable的详细字符串 void PrintStackTrace();jvm打印异常,默认此方法,打印的异常信息是最全的 |
1 2 3 4 | try {} catch(){} finally{ }; |
1 2 3 4 5 6 7 | ArrayIndexOutofboundsException 数组索引越界异常 NullpointerException;空指针异常 ClassCastException IndexOutOfBoundsException 索引越界异常 ConcurrentModificationException ArithmeticException 算术运算异常 NumberFormatException 数字格式化异常 |
FileNotFoundException 文件地址异常
IOException
ParseException 解析异常
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) | 黑马程序员IT技术论坛 X3.2 |