javaHashMapLinkedHashMapTreeMap.docx

上传人:b****5 文档编号:2929634 上传时间:2022-11-16 格式:DOCX 页数:12 大小:1.04MB
下载 相关 举报
javaHashMapLinkedHashMapTreeMap.docx_第1页
第1页 / 共12页
javaHashMapLinkedHashMapTreeMap.docx_第2页
第2页 / 共12页
javaHashMapLinkedHashMapTreeMap.docx_第3页
第3页 / 共12页
javaHashMapLinkedHashMapTreeMap.docx_第4页
第4页 / 共12页
javaHashMapLinkedHashMapTreeMap.docx_第5页
第5页 / 共12页
点击查看更多>>
下载资源
资源描述

javaHashMapLinkedHashMapTreeMap.docx

《javaHashMapLinkedHashMapTreeMap.docx》由会员分享,可在线阅读,更多相关《javaHashMapLinkedHashMapTreeMap.docx(12页珍藏版)》请在冰豆网上搜索。

javaHashMapLinkedHashMapTreeMap.docx

javaHashMapLinkedHashMapTreeMap

河南城建学院计算机科学与工程学院

《可视化编程技术(JAVA)》实验报告

实验名称:

实验五 成绩:

___________

专业班级:

_姓名:

___学号:

___

实 验 日 期:

2014 年10月22 日

软件环境:

WindowsXP实验工具:

MyEclipse

硬件环境:

CPU3.0GHZ,内存2G

一、实验目的

 1、掌握文件类File的基本用法。

2、掌握Map、HashMap、LinkedHashMap、TreeMap等用法。

3、掌握迭代器的使用。

二、实验过程及内容

1、创建java项目,创建各个类。

2、根据要求编写各种类的程序。

3、代码如下:

packagecn.edu.hncj;

importjava.io.File;

classTheFile{

publicstaticvoidmain(String[]args){

FilediskC=newFile("C:

/");

FiletestFile=newFile(diskC,"test");

System.out.println(diskC.getAbsolutePath()+"是否存在:

"+diskC.exists());

System.out.println(testFile.getAbsolutePath()+"是否存在:

"+testFile.exists());

}

}

packagecn.edu.hncj;

importjava.io.File;

importjava.io.IOException;

 

classTheFile2{

publicstaticvoidmain(String[]args){

FiletestFile=newFile("c:

\\test");

System.out.println(testFile.getAbsolutePath()+"是否存在:

"+testFile.exists());

try{

testFile.createNewFile();

}

catch(IOExceptione){

e.printStackTrace();

}

System.out.println(testFile.getAbsolutePath()+"是否存在:

"+testFile.exists());

FiletestDir=newFile("c:

\\a\\b\\c");

System.out.println(testDir.getAbsolutePath()+"是否存在:

"+testDir.exists());

testDir.mkdirs();

System.out.println(testDir.getAbsolutePath()+"是否存在:

"+testDir.exists());

}

}

packagecn.edu.hncj;

importjava.util.*;

publicclassHashMapDemo{

publicstaticvoidmain(String[]args){

HashMapmap=newHashMap();

map.put(1,"pds");

map.put(2,"sq");

map.put(3,"ly");

map.put(4,"fs");

//map.put(4,"xy");

System.out.println("containsKey:

"+map.containsKey

(1));

System.out.println(map);

System.out.println("get:

"+map.get

(2));

map.put(5,null);

System.out.println("get:

"+map.get(null));

Collectioncoll=map.values();

System.out.println(coll);

}

}

packagecn.edu.hncj;

importjava.util.*;

publicclassHashMapDemo2{

publicstaticvoidmain(String[]args){

HashMapmap=newHashMap();

//LinkedHashMapmap=newLinkedHashMap();

//TreeMapmap=newTreeMap();

map.put(2,"pds");

map.put(1,"sq");

map.put(4,"ly");

map.put(3,"fs");

Iteratorit=map.keySet().iterator();

while(it.hasNext()){

Integeri=(Integer)it.next();

System.out.println(i+":

"+map.get(i));

}

}

}

packagecn.edu.hncj;

importjava.util.*;

classHashMapDemo1{

publicstaticvoidmain(Stringargs[]){

HashMaphm=newHashMap();

hm.put("John",newDouble(34.34));

hm.put("Tom",newDouble(23.22));

hm.put("Jane",newDouble(78.00));

hm.put("Smith",newDouble(99.22));

hm.put("Rose",newDouble(-19.88));

Iteratorit=hm.keySet().iterator();

while(it.hasNext()){

Stringi=(String)it.next();

System.out.println("key:

"+i+"value:

"+hm.get(i));

}

}

}

三、实验结果

实验结果如下:

图1

图2

图3

图4

图5

图6

图7

图8

图9

图10

图11

图12

图13

四、出现问题及解决方案

在这次试验中SortedMap程序不会写,其他的Map类只会写些简单的。

这次的实验前两个是照这课本打的,后几个是自己编的,其中的功能是因为程序太短XX的一些功能,后面的Map类比较了HashMap、LinkedHashMap、TreeMap的区别。

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 高中教育 > 语文

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1