Warning: Undefined array key "night" in /www/wwwroot/dhaomu.com/wp-content/themes/b2/header.php on line 18

Java技术善用二维数组HashBasedTable双键Map

Java技术善用二维数组,HashBasedTable双键Map

代码演示

		Table<Integer, Integer, Integer> table = HashBasedTable.<Integer, Integer, Integer>create();
		table.put(1, 2, 3);
		//允许row和column确定的二维点重复
		table.put(1, 6, 3);
		//判断row和column确定的二维点是否存在
		if (table.contains(1, 2)) {
			table.put(1, 4, 4);
			table.put(2, 5, 4);
		}
		System.out.println(table);
		//获取column为5的数据集
		Map<Integer, Integer> column = table.column(5);
		System.out.println("column:" + column);
		//获取column为5的数据集2
		Map<Integer, Integer> column2 = table.column(2);
		System.out.println("column2:" + column2);
		//获取rowkey为1的数据集
		Map<Integer, Integer> row = table.row(1);
		System.out.println("row:" + row);
		//获取rowKey为1,columnKey为2的的结果
		Integer value = table.get(1, 2);
		System.out.println("value:" + value);
		//判断是否包含columnKey的值
		System.out.println("containsColumn:" + table.containsColumn(3));
		//判断是否包含rowKey为1的视图
		System.out.println("containsRow:" + table.containsRow(1));
		//判断是否包含值为2的集合
		System.out.println("containsValue:" + table.containsValue(2));
		//将table转换为Map套Map格式
		Map<Integer, Map<Integer, Integer>> rowMap = table.rowMap();
		System.out.println("rowMap:" + rowMap);
		//获取所有的rowKey值的集合
		Set<Integer> keySet = table.rowKeySet();
		System.out.println("keySet:" + keySet);
		//删除rowKey为1,columnKey为2的元素,返回删除元素的值
		Integer res = table.remove(1, 2);
		//清空集合
		table.clear();
		System.out.println(res);
		System.out.println(table);
		
		
		执行结果:
		{1={4=4, 2=3, 6=3}, 2={5=4}}
		column:{2=4}
		column2:{1=3}
		row:{4=4, 2=3, 6=3}
		value:3
		containsColumn:false
		containsRow:true
		containsValue:false
		rowMap:{1={4=4, 2=3, 6=3}, 2={5=4}}
		keySet:[1, 2]
		3
		{}
温馨提示:
1.本站大部分内容均收集于网络!若内容若侵犯到您的权益,请发送邮件至:duhaomu@163.com,我们将第一时间处理!
2.资源所需价格并非资源售卖价格,是收集、整理、编辑详情以及本站运营的适当补贴,并且本站不提供任何免费技术支持。
3.所有资源仅限于参考和学习,版权归原作者所有,更多请阅读网站声明

给TA赞赏
共{{data.count}}人
人已赞赏
编程技巧

EcShop教程:显示某商品销售累计效果的实现代码

2015-12-3 9:00:00

编程技巧

PHP教程DOS实现数字雨代码

2015-12-6 9:00:00

0 条回复 A文章作者 M管理员

Warning: Trying to access array offset on value of type null in /www/wwwroot/dhaomu.com/wp-content/themes/b2/functions.php on line 3914

Warning: Trying to access array offset on value of type null in /www/wwwroot/dhaomu.com/wp-content/themes/b2/functions.php on line 3914
----《》
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索