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

惠州网站制作费用制作公司网页的步骤

惠州网站制作费用,制作公司网页的步骤,通州区住房和城乡建设部网站,搭建网站的软件Map Map集合概述和特点 概述: 将键映射到值的对象 一个映射不能包含重复的键 每个键最多只能映射到一个值 Map接口和Collection接口的不同 Map是双列的,Collection是单列的 Map的键唯一,Collection的子体系Set是唯一的 Map集合的数据结构针对键有效,跟…

Map

Map集合概述和特点

概述:
将键映射到值的对象
一个映射不能包含重复的键
每个键最多只能映射到一个值
Map接口和Collection接口的不同
Map是双列的,Collection是单列的
Map的键唯一,Collection的子体系Set是唯一的
Map集合的数据结构针对键有效,跟值无关;Collection集合的数据结构是针对元素有效

Map集合的功能概述

a:添加功能
V put(K key,V value):添加元素。这个其实还有另一个功能替换
如果键是第一次存储,就直接存储元素,返回null
如果键不是第一次存在,就用值把以前的值替换掉,返回以前的值
b:删除功能
void clear():移除所有的键值对元素
V remove(Object key):根据键删除键值对元素,并把值返回
c:判断功能
boolean containsKey(Object key):判断集合是否包含指定的键
boolean containsValue(Object value):判断集合是否包含指定的值
boolean isEmpty():判断集合是否为空
d:获取功能
Set<Map.Entry<K,V>> entrySet(): 返回一个键值对的Set集合
V get(Object key):根据键获取值
Set keySet():获取集合中所有键的集合
Collection values():获取集合中所有值的集合
e:长度功能
int size():返回集合中的键值对的对数

Map集合的遍历之键找值

获取所有键的集合
遍历键的集合,获取到每一个键
根据键找值

public class Test4 {public static void main(String[] args) {HashMap<Phone,String> map = new HashMap<>();map.put(new Phone("Apple",7000),"美国");map.put(new Phone("Sony",5000),"日本");map.put(new Phone("Huawei",6000),"中国");Set<Phone> phones = map.keySet();Iterator<Phone> iterator = phones.iterator();while (iterator.hasNext()){Phone next = iterator.next();System.out.println(next.getBrand()+"=="+next.getPrice()+"=="+map.get(next));}}
}
class Phone{private String Brand;private int Price;public Phone(String brand, int price) {Brand = brand;Price = price;}public String getBrand() {return Brand;}public void setBrand(String brand) {Brand = brand;}public int getPrice() {return Price;}public void setPrice(int price) {Price = price;}
}

获取所有键值对对象的集合
遍历键值对对象的集合,获取到每一个键值对对象
根据键值对对象找键和值

public class Test4 {public static void main(String[] args) {HashMap<Phone,String> map = new HashMap<>();map.put(new Phone("Apple",7000),"美国");map.put(new Phone("Sony",5000),"日本");map.put(new Phone("Huawei",6000),"中国");Set<Map.Entry<Phone, String>> entries = map.entrySet();for (Map.Entry<Phone, String> entry : entries) {System.out.println(entry.getKey().getBrand()+"==="+entry.getKey().getPrice()+"==="+entry.getValue());}}
}

一般来说建议使用entrySet遍历方式,其效率高

LinkedHashMap的概述和使用

LinkedHashMap的概述: Map 接口的哈希表和链接列表实现,具有可预知的迭代顺序LinkedHashMap的特点: 底层的数据结构是链表和哈希表 元素有序 并且唯一
元素的有序性由链表数据结构保证 唯一性由 哈希表数据结构保证
Map集合的数据结构只和键有关

TreeMap集合

TreeMap 键不允许插入null
TreeMap: 键的数据结构是红黑树,可保证键的排序和唯一性
排序分为自然排序和比较器排序
线程是不安全的效率比较高
TreeMap集合排序:
实现Comparable接口,重写CompareTo方法
使用比较器

TreeMap集合的遍历

public class Test4 {public static void main(String[] args) {TreeMap<Phone,String> map = new TreeMap<>();map.put(new Phone("Apple",7000),"美国");map.put(new Phone("Sony",5000),"日本");map.put(new Phone("Huawei",6000),"中国");Set<Phone> phones = map.keySet();Iterator<Phone> iterator = phones.iterator();while(iterator.hasNext()){Phone next = iterator.next();System.out.println(next.getBrand()+"==="+next.getPrice()+"==="+map.get(next));}}
}
class Phone implements Comparable<Phone>{private String Brand;private int Price;public Phone(String brand, int price) {Brand = brand;Price = price;}public String getBrand() {return Brand;}public void setBrand(String brand) {Brand = brand;}public int getPrice() {return Price;}public void setPrice(int price) {Price = price;}@Overridepublic int compareTo(Phone o) {return this.getPrice() - o.getPrice();}
}

集合嵌套之HashMap嵌套HashMap

基础班
张三 20
李四 22
就业班
王五 21
赵六 23

public class Test5 {public static void main(String[] args) {HashMap<String, Integer> map = new HashMap<>();map.put("张三",20);map.put("李四",22);HashMap<String, Integer> map1 = new HashMap<>();map1.put("王五",21);map1.put("赵六",23);HashMap<String, HashMap<String, Integer>> mapmax = new HashMap<>();mapmax.put("基础班",map);mapmax.put("就业班",map1);Set<Map.Entry<String, HashMap<String, Integer>>> entries = mapmax.entrySet();for (Map.Entry<String, HashMap<String, Integer>> entry : entries) {System.out.println(entry.getKey());Set<Map.Entry<String, Integer>> entries1 = entry.getValue().entrySet();for (Map.Entry<String, Integer> stringIntegerEntry : entries1) {System.out.println("	"+stringIntegerEntry.getKey()+"     "+stringIntegerEntry.getValue());}}}
}

Arraylist嵌套HashMap

public class Test3 {public static void main(String[] args) {HashMap<String, String> map = new HashMap<>();map.put("周瑜","小乔");map.put("吕布","貂蝉");HashMap<String, String> map1 = new HashMap<>();map1.put("郭靖","黄蓉");map1.put("杨过","小龙女");HashMap<String, String> map2 = new HashMap<>();map2.put("令狐冲","任盈盈");map2.put("林平之","岳灵珊");ArrayList<HashMap<String, String>> list = new ArrayList<>();list.add(map);list.add(map1);list.add(map2);for (HashMap<String, String> s : list) {Set<String> strings = s.keySet();for (String s1 : strings) {String s2 = s.get(s1);System.out.println("	"+s1+"---"+s2);}System.out.println();}}
}

Collections工具类的概述和常见方法

A:Collections类概述: 针对集合操作 的工具类
B:Collections成员方法
public static void sort(List list): 排序,默认按照自然顺序
public static int binarySearch(List<> list,T key): 二分查找
public static T max(Collection<> coll): 获取最大值
public static void reverse(List<> list): 反转
public static void shuffle(List<> list): 随机置换

模拟斗地主洗牌和发牌并对牌进行排序的代码实现
在这里插入图片描述

public class Test4 {public static void main(String[] args) {//A://案例演示://模拟斗地主洗牌和发牌,牌没有排序//得有一副牌//生成54张牌放到牌盒里面String[] colors = {"?", "?", "?", "?"};String[] nums = {"3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A", "2"};HashMap<Integer, String> map = new HashMap<Integer, String>();ArrayList<Integer> list = new ArrayList<>();int index = 0;for (String num : nums) {for (String color : colors) {map.put(index, color.concat(num));list.add(index);index++;}}map.put(index, "☆");list.add(index);index++;map.put(index, "★");list.add(index);//洗牌Collections.shuffle(list);//发牌TreeSet<Integer> 高进 = new TreeSet<>();TreeSet<Integer> 刀仔 = new TreeSet<>();TreeSet<Integer> 星仔 = new TreeSet<>();TreeSet<Integer> 底牌 = new TreeSet<>();// 高进 = (ArrayList<String>) pokerBox.subList(0,17);// 高进 0  3 6 9//刀仔 1 4 7 10//  星仔 2 5 8 11for (int i = 0; i < list.size(); i++) {if (i >= list.size() - 3) {底牌.add(list.get(i));} else if (i % 3 == 0) {高进.add(list.get(i));} else if (i % 3 == 1) {刀仔.add(list.get(i));} else {星仔.add(list.get(i));}}//看牌lookPoker(map,高进,"高进");lookPoker(map,刀仔,"刀仔");lookPoker(map,星仔,"星仔");lookPoker(map,底牌,"底牌");}public static void lookPoker(HashMap<Integer, String> map, TreeSet<Integer> list, String name) {System.out.println(name);for (Integer s : list) {System.out.print(map.get(s));}System.out.println();}
}

Map中的键唯一,但是当存储自定义对象时,需要重写Hashcode和equals方法

http://www.yayakq.cn/news/845498/

相关文章:

  • 企业网站建设销售话术sem推广软件
  • 网站页面设计基础教程vs2012网站开发
  • 古典风格网站模板wordpress 分享 微信
  • 产品包装设计网站qml 网站开发
  • 贵州建筑网站iis7.5 网站配置
  • 网站 前台后台网站建设也笔试
  • 网站关键词排名下降h5免费制作平台企业秀
  • 手机网站建设的整体流程图wordpress server error
  • 邢台哪里有做网站的全国建设项目验收信息网站
  • 桂林论坛网网站电话网站建设公司厦门有哪些
  • 南昌网站开发长沙网站建设服务公司
  • 网站建设策划需要涉及怎么建立淘宝客网站
  • 做线上兼职的网站在北京做网站seo多少钱
  • 亚马逊商标备案是否必须做网站asp.net获取网站的域名
  • 重庆网络建站网站的标题
  • 做公司网站需不需要注册购物网站APP
  • 西安网络推广网站优化重庆seo排名扣费
  • 织梦房产网站模板10类地方网站 总有适合你做的
  • 比较容易做的网站甘肃建筑工程网
  • 网站模板怎么设计做网站编辑需要学什么
  • 哪些网站做的海报比较高大上自己做网站排名
  • php做的网站首页是什么文件怎么做原创短视频网站
  • 嘉兴云推广网站在360上做网站多少钱
  • 网站建设分金手指排名十做外贸网站需要注意什么
  • 永久免费的网站服务器有哪些软件腾讯短网址生成
  • 做图素材网站开通会员哪个好wordpress怎么备份数据库
  • 哪个网站可以帮人做ppt黄岛区网站建设
  • z怎么建设视频网站网络营销课程去哪里学
  • 网站备案成功后该怎么做如何制作一个动态的网站的登录详细步骤页面
  • 网站建设费按多少年摊销旭辉网站建设