java130-treemap类
2022/6/26 1:25:38
本文主要是介绍java130-treemap类,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
public class Department {
private String code;//部门编号
private String name;//部门名字
private int quanity;//部门人员数量
public void setCode(String code) {
this.code = code;
}
public String getCode() {
return code;
}
public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void setQuanity(int quanity) {
this.quanity = quanity;
}
public int getQuanity() {
return quanity;
}
}
测试类
//treemap实现类
import java.util.Collection;
import java.util.Comparator;
import java.util.TreeMap;
public class test69 {
public static void main(String[] args){
TreeMap depTree;
depTree = new TreeMap(new Comparator() {
@Override
public int compare(Object
k1, Object
k2) {
Integer intk1 = (Integer) k1;
Integer intk2 = (Integer) k2;
if (intk1.intValue() > intk2.intValue()) {
return -1;
} else if (intk1.intValue() < intk2.intValue())
return 1;
return 0;
}
});
Department dep0=new Department();
dep0.setCode("dep400");
dep0.setName("研发部");
dep0.setQuanity(50);
Department dep1=new Department();
dep1.setCode("dep200");
dep1.setName("人事部");
dep1.setQuanity(30);
Department dep2=new Department();
dep2.setCode("dep100");
dep2.setName("事业部");
dep2.setQuanity(20);
Department dep3=new Department();
dep3.setCode("dep100");
dep3.setName("市场部");
dep3.setQuanity(100);
//存储数据
depTree.put(new Integer(100),dep3);
depTree.put(new Integer(50),dep0);
depTree.put(new Integer(80),dep1);
depTree.put(new Integer(10),dep2);
Collection coll=depTree.values();
for(Object o:coll){
Department depTemp=(Department)o;
System.out.println(depTemp.getName()+"\t"+depTemp.getCode());
}
}
}
运行结果
这篇关于java130-treemap类的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-11-23Springboot应用的多环境打包入门
- 2024-11-23Springboot应用的生产发布入门教程
- 2024-11-23Python编程入门指南
- 2024-11-23Java创业入门:从零开始的编程之旅
- 2024-11-23Java创业入门:新手必读的Java编程与创业指南
- 2024-11-23Java对接阿里云智能语音服务入门详解
- 2024-11-23Java对接阿里云智能语音服务入门教程
- 2024-11-23JAVA对接阿里云智能语音服务入门教程
- 2024-11-23Java副业入门:初学者的简单教程
- 2024-11-23JAVA副业入门:初学者的实战指南