当前位置: 首页 > news >正文

福田附近公司做网站建设多少钱竞价代运营公司哪家好

福田附近公司做网站建设多少钱,竞价代运营公司哪家好,电商加盟网站建设,长春大学目录Map集合体系一、Map集合的概述二、Map集合体系特点三、Map集合常用API四、Map集合的遍历4.1 Map集合的遍历方式一:键找值4.2 Map集合的遍历方式二:键值对4.3 Map集合的遍历方式三:lambda表达式五、Map集合案例-统计投票人数六、Map集合的…

目录

      • Map集合体系
        • 一、Map集合的概述
        • 二、Map集合体系特点
        • 三、Map集合常用API
        • 四、Map集合的遍历
          • 4.1 Map集合的遍历方式一:键找值
          • 4.2 Map集合的遍历方式二:键值对
          • 4.3 Map集合的遍历方式三:lambda表达式
        • 五、Map集合案例-统计投票人数
        • 六、Map集合的实现类HashMap
        • 七、Map集合的实现类LinkedHashMap
        • 八、Map集合的实现类TreeMap
        • 九、集合的嵌套

Map集合体系

在这里插入图片描述

一、Map集合的概述

Map集合是一种双列集合,每个元素包含两个数据。
Map集合的每个元素的格式:key=value(键值对元素),一一对应。
Map集合也被称为“键值对集合”。

  • Collection集合的格式: [元素1,元素2,元素3…]
  • Map集合的完整格式:{key1=value1 , key2=value2 , key3=value3 , …}

二、Map集合体系特点

使用最多的Map集合是HashMap。

  • Map集合的特点都是由键决定的。
  • Map集合的键是无序,不重复的,无索引的,值不做要求(可以重复)。
  • Map集合后面重复的键对应的值会覆盖前面重复键的值。
  • Map集合的键值对都可以为null。

Map集合实现类特点

  • HashMap:元素按照键是无序,不重复,无索引,值不做要求。(与Map体系一致)
  • LinkedHashMap:元素按照键是有序,不重复,无索引,值不做要求。
  • TreeMap:元素按照建是排序,不重复,无索引的,值不做要求。

三、Map集合常用API

Map是双列集合的祖宗接口,它的功能是全部双列集合都可以继承使用的。
在这里插入图片描述

/**目标:Map集合的常用API(重点中的重点)- 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集合)。- public boolean containKey(Object key):判断该集合中是否有此键。- public boolean containValue(Object value):判断该集合中是否有此值。*/
public class MapDemo {public static void main(String[] args) {// 1.添加元素: 无序,不重复,无索引。Map<String , Integer> maps = new HashMap<>();maps.put("iphoneX",10);maps.put("娃娃",20);maps.put("iphoneX",100);//  Map集合后面重复的键对应的元素会覆盖前面重复的整个元素!maps.put("huawei",100);maps.put("生活用品",10);maps.put("手表",10);// {huawei=100, 手表=10, 生活用品=10, iphoneX=100, 娃娃=20}System.out.println(maps);// 2.清空集合
//        maps.clear();
//        System.out.println(maps);// 3.判断集合是否为空,为空返回true ,反之!System.out.println(maps.isEmpty());// 4.根据键获取对应值:public V get(Object key)Integer key = maps.get("huawei");System.out.println(key);System.out.println(maps.get("生活用品")); // 10System.out.println(maps.get("生活用品2")); // null// 5.根据键删除整个元素。(删除键会返回键的值)System.out.println(maps.remove("iphoneX"));System.out.println(maps);// 6.判断是否包含某个键 ,包含返回true ,反之System.out.println(maps.containsKey("娃娃"));  // trueSystem.out.println(maps.containsKey("娃娃2"));  // falseSystem.out.println(maps.containsKey("iphoneX")); // false// 7.判断是否包含某个值。System.out.println(maps.containsValue(100));  //System.out.println(maps.containsValue(10));  //System.out.println(maps.containsValue(22)); //// {huawei=100, 手表=10, 生活用品=10, 娃娃=20}// 8.获取全部键的集合:public Set<K> keySet()Set<String> keys = maps.keySet();System.out.println(keys);System.out.println("------------------------------");// 9.获取全部值的集合:Collection<V> values();Collection<Integer> values = maps.values();System.out.println(values);// 10.集合的大小System.out.println(maps.size()); // 4// 11.合并其他Map集合。(拓展)Map<String , Integer> map1 = new HashMap<>();map1.put("java1", 1);map1.put("java2", 100);Map<String , Integer> map2 = new HashMap<>();map2.put("java2", 1);map2.put("java3", 100);map1.putAll(map2); // 把集合map2的元素拷贝一份到map1中去System.out.println(map1);//{java3=100, java2=1, java1=1}System.out.println(map2);//{java3=100, java2=1}
}

四、Map集合的遍历

4.1 Map集合的遍历方式一:键找值

方式一:键找值的方式遍历:先获取Map集合全部的键,再根据遍历键找值。

/**目标:Map集合的遍历方式一:键找值a.“键找值”的方式遍历Map集合。1.先获取Map集合的全部键的Set集合。2.遍历键的Set集合,然后通过键找值。小结:代码简单,需要记住!*/
public class MapDemo01 {public static void main(String[] args) {Map<String , Integer> maps = new HashMap<>();// 1.添加元素: 无序,不重复,无索引。maps.put("娃娃",30);maps.put("iphoneX",100);maps.put("huawei",1000);maps.put("生活用品",10);maps.put("手表",10);System.out.println(maps);// maps = {huawei=1000, 手表=10, 生活用品=10, iphoneX=100, 娃娃=30}// 1、键找值:第一步:先拿到集合的全部键。Set<String> keys = maps.keySet();// 2、第二步:遍历每个键,根据键提取值for (String key : keys) {int value = maps.get(key);System.out.println(key + "===>" + value);}}
}
4.2 Map集合的遍历方式二:键值对

方式二:键值对的方式遍历,把“键值对“看成一个整体,难度较大。

/**目标:Map集合的遍历方式。b.“键值对”的方式遍历:1.把Map集合转换成一个Set集合:Set<Map.Entry<K, V>> entrySet();2.此时键值对元素的类型就确定了,类型是键值对实体类型:Map.Entry<K, V>3.接下来就可以用foreach遍历这个Set集合,类型用Map.Entry<K, V>*/
public class MapDemo02 {public static void main(String[] args) {Map<String , Integer> maps = new HashMap<>();// 1.添加元素: 无序,不重复,无索引。maps.put("娃娃",30);maps.put("iphoneX",100);maps.put("huawei",1000);maps.put("生活用品",10);maps.put("手表",10);System.out.println(maps);// maps = {huawei=1000, 手表=10, 生活用品=10, iphoneX=100, 娃娃=30}/**maps = {huawei=1000, 手表=10, 生活用品=10, iphoneX=100, 娃娃=30}👇使用foreach遍历map集合.发现Map集合的键值对元素直接是没有类型的。所以不可以直接foreach遍历集合。👇可以通过调用Map的方法 entrySet把Map集合转换成Set集合形式  maps.entrySet();👇Set<Map.Entry<String,Integer>> entries =  maps.entrySet();[(huawei=1000), (手表=10), (生活用品=10), (iphoneX=100), (娃娃=30)]entry👇此时可以使用foreach遍历*/// 1、把Map集合转换成Set集合Set<Map.Entry<String, Integer>> entries = maps.entrySet();// 2、开始遍历for(Map.Entry<String, Integer> entry : entries){String key = entry.getKey();int value = entry.getValue();System.out.println(key + "====>" + value);}}
}
4.3 Map集合的遍历方式三:lambda表达式

方式三:JDK 1.8开始之后的新技术:Lambda表达式。

/**目标:Map集合的遍历方式。c.JDK 1.8开始之后的新技术:Lambda表达式。*/
public class MapDemo03 {public static void main(String[] args) {Map<String , Integer> maps = new HashMap<>();// 1.添加元素: 无序,不重复,无索引。maps.put("娃娃",30);maps.put("iphoneX",100);//  Map集合后面重复的键对应的元素会覆盖前面重复的整个元素!maps.put("huawei",1000);maps.put("生活用品",10);maps.put("手表",10);System.out.println(maps);//  maps = {huawei=1000, 手表=10, 生活用品=10, iphoneX=100, 娃娃=30}//        maps.forEach(new BiConsumer<String, Integer>() {
//            @Override
//            public void accept(String key, Integer value) {
//                System.out.println(key + "--->" + value);
//            }
//        });maps.forEach((k, v) -> {System.out.println(k + "--->" + v);});}
}

五、Map集合案例-统计投票人数

需求:
某个班级80名学生,现在需要组成秋游活动,班长提供了四个景点依次是(A、B、C、D),每个学生只能选择一个景点,请统计出最终哪个景点想去的人数最多。

/**需求:统计投票人数*/
public class MapTest1 {public static void main(String[] args) {// 1、把80个学生选择的数据拿进来。String[] selects = {"A" , "B", "C", "D"};StringBuilder sb = new StringBuilder();Random r = new Random();for (int i = 0; i < 80; i++) {sb.append(selects[r.nextInt(selects.length)]);}System.out.println(sb);// 2、定义一个Map集合记录最终统计的结果: A=30 B=20 C=20 D=10  键是景点 值是选择的数量Map<Character, Integer> infos = new HashMap<>(); //// 3、遍历80个学生选择的数据for (int i = 0; i < sb.length(); i++) {// 4、提取当前选择景点字符char ch = sb.charAt(i);// 5、判断Map集合中是否存在这个键if(infos.containsKey(ch)){// 让其值 + 1infos.put(ch , infos.get(ch) + 1);}else {// 说明此景点是第一次被选infos.put(ch , 1);}}// 4、输出集合System.out.println(infos);}
}

六、Map集合的实现类HashMap

  • HashMap是Map里面的一个实现类。特点都是由键决定的:无序、不重复、无索引
  • 没有额外需要学习的特有方法,直接使用Map里面的方法就可以了。
  • HashMap跟HashSet底层原理是一模一样的,都是哈希表结构,只是HashMap的每个元素包含两个值而已。

实际上:Set系列集合的底层就是Map实现的,只是Set集合中的元素只要键数据,不要值数据而已

HashMap的特点和底层原理

  1. 由键决定:无序、不重复、无索引。HashMap底层是哈希表结构的。
  2. 依赖hashCode方法和equals方法保证键的唯一。
  3. 如果键要存储的是自定义对象,需要重写hashCode和equals方法。
  4. 基于哈希表。增删改查的性能都较好。

七、Map集合的实现类LinkedHashMap

  • 由键决定:有序、不重复、无索引。
  • 这里的有序指的是保证存储和取出的元素顺序一致
  • 原理:底层数据结构是依然哈希表,只是每个键值对元素又额外的多了一个双链表的机制记录存储的顺序

八、Map集合的实现类TreeMap

  • 由键决定特性:不重复、无索引、可排序
  • 可排序:按照键数据的大小默认升序(有小到大)排序。只能对键排序。
  • 注意:TreeMap集合是一定要排序的,可以默认排序,也可以将键按照指定的规则进行排序
    TreeMap跟TreeSet一样底层原理是一样的。

TreeMap集合自定义排序规则有2种

  • 类实现Comparable接口,重写比较规则。
  • 集合自定义Comparator比较器对象,重写比较规则。

九、集合的嵌套

需求:不同在于可以选多个景点

某个班级多名学生,现在需要组成秋游活动,班长提供了四个景点依次是(A、B、C、D),每个学生可以选择多个景点,请统计出最终哪个景点想去的人数最多。

/**需求:统计投票人数*/
public class MapTest4 {public static void main(String[] args) {// 1、要求程序记录每个学生选择的情况。// 使用一个Map集合存储。Map<String, List<String>> data = new HashMap<>();// 2、把学生选择的数据存入进去。List<String> selects = new ArrayList<>();Collections.addAll(selects, "A", "C");data.put("罗勇", selects);List<String> selects1 = new ArrayList<>();Collections.addAll(selects1, "B", "C" , "D");data.put("胡涛", selects1);List<String> selects2 = new ArrayList<>();Collections.addAll(selects2 , "A",  "B", "C" , "D");data.put("刘军", selects2);System.out.println(data);// 3、统计每个景点选择的人数。Map<String, Integer> infos = new HashMap<>(); // {}// 4、提取所有人选择的景点的信息。Collection<List<String>> values = data.values();System.out.println(values);// values = [[A, B, C, D], [B, C, D], [A, C]]//             valuefor (List<String> value : values) {for (String s : value) {// 有没有包含这个景点if(infos.containsKey(s)){infos.put(s, infos.get(s) + 1);}else {infos.put(s , 1);}}}System.out.println(infos);}
}

文章转载自:
http://displode.bfmq.cn
http://virus.bfmq.cn
http://bibliophile.bfmq.cn
http://serotype.bfmq.cn
http://nevertheless.bfmq.cn
http://sexagesimal.bfmq.cn
http://velour.bfmq.cn
http://goosy.bfmq.cn
http://shed.bfmq.cn
http://cherub.bfmq.cn
http://musically.bfmq.cn
http://decemvirate.bfmq.cn
http://lynchpin.bfmq.cn
http://bagging.bfmq.cn
http://jericho.bfmq.cn
http://dogfall.bfmq.cn
http://montessorian.bfmq.cn
http://massy.bfmq.cn
http://warless.bfmq.cn
http://lighthouseman.bfmq.cn
http://interisland.bfmq.cn
http://invariant.bfmq.cn
http://bloodstock.bfmq.cn
http://dyestuff.bfmq.cn
http://vortices.bfmq.cn
http://cosignatory.bfmq.cn
http://jaguarondi.bfmq.cn
http://jointed.bfmq.cn
http://salpinges.bfmq.cn
http://corporator.bfmq.cn
http://excussion.bfmq.cn
http://factor.bfmq.cn
http://lineup.bfmq.cn
http://bodhran.bfmq.cn
http://cellarer.bfmq.cn
http://incohesive.bfmq.cn
http://chlorophyll.bfmq.cn
http://toepiece.bfmq.cn
http://paralytic.bfmq.cn
http://biliprotein.bfmq.cn
http://lignivorous.bfmq.cn
http://indecorum.bfmq.cn
http://presbyterian.bfmq.cn
http://remontant.bfmq.cn
http://chrismal.bfmq.cn
http://sandman.bfmq.cn
http://inhumanly.bfmq.cn
http://jerrican.bfmq.cn
http://tetrodotoxin.bfmq.cn
http://communistic.bfmq.cn
http://smitten.bfmq.cn
http://minotaur.bfmq.cn
http://improved.bfmq.cn
http://isopach.bfmq.cn
http://nonreduction.bfmq.cn
http://levallois.bfmq.cn
http://playgoer.bfmq.cn
http://sextillion.bfmq.cn
http://unmoving.bfmq.cn
http://actinotheraphy.bfmq.cn
http://stove.bfmq.cn
http://clumpy.bfmq.cn
http://arris.bfmq.cn
http://pryer.bfmq.cn
http://tollman.bfmq.cn
http://labyrinth.bfmq.cn
http://gaiety.bfmq.cn
http://seatmate.bfmq.cn
http://sinusoid.bfmq.cn
http://chiropodist.bfmq.cn
http://clubber.bfmq.cn
http://isolt.bfmq.cn
http://teminism.bfmq.cn
http://mace.bfmq.cn
http://heresiologist.bfmq.cn
http://carbolize.bfmq.cn
http://retinue.bfmq.cn
http://pilular.bfmq.cn
http://satisfaction.bfmq.cn
http://beau.bfmq.cn
http://flexuose.bfmq.cn
http://covariant.bfmq.cn
http://nonimmigrant.bfmq.cn
http://thaumaturgical.bfmq.cn
http://sheol.bfmq.cn
http://calcar.bfmq.cn
http://monecious.bfmq.cn
http://purga.bfmq.cn
http://modernus.bfmq.cn
http://tabasco.bfmq.cn
http://pupae.bfmq.cn
http://mesophile.bfmq.cn
http://preference.bfmq.cn
http://carl.bfmq.cn
http://trichlorfon.bfmq.cn
http://semifinal.bfmq.cn
http://daylong.bfmq.cn
http://feh.bfmq.cn
http://incunabulum.bfmq.cn
http://intolerability.bfmq.cn
http://www.dt0577.cn/news/105212.html

相关文章:

  • flash网站建设教程视频查排名的网站
  • 产品如何推广网站站长seo推广
  • 深圳有做网站的公司太原关键词排名推广
  • 官方网站建设平台郑州网站推广电话
  • 国外做ppt的网站深圳市住房和建设局官网
  • 做网站链接怎么做坚持
  • 企业建设网站要注意的要素厦门百度竞价
  • 苏州建设网站平台4414站长平台
  • 卖货网站平台病毒式营销案例
  • 图片做网站目前引流最好的平台
  • 黄浦网站建设2023近期舆情热点事件
  • 介绍自己做的电影网站seo运营推广
  • 物联网平台是干什么的用的seo优化实训报告
  • 网站设计服务流程百度一下首页网址
  • 网站建设的er图企业营销策划书模板
  • 深圳网站制作专业公司热点新闻事件及观点
  • 网站推广公司兴田德润百度咨询电话 人工客服
  • 旅游网站建设系统石家庄谷歌seo
  • 巩义市网站建设培训班营销策略ppt
  • 3d云设计网站开发百度搜索推广的五大优势
  • 仿站工具箱网页版东莞百度seo
  • 东莞塘厦网站制作防疫优化措施
  • 网络管理工具昆明seocn整站优化
  • 企业把网站关闭原因引擎搜索技巧
  • 自己做网站nas交换链接适合哪些网站
  • 个人网站做微擎ds2600ii色带
  • 做馋嘴小栈官方网站百度指数是什么意思
  • wordpress 无法评论包头seo
  • 企业安全文化建设的核心内容seo网站推广工作内容
  • 河南省中原建设有限公司网站温州网站建设