javaHashMapLinkedHashMapTreeMapWord下载.docx

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

javaHashMapLinkedHashMapTreeMapWord下载.docx

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

javaHashMapLinkedHashMapTreeMapWord下载.docx

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());

}

}

importjava.io.IOException;

 

classTheFile2{

publicstaticvoidmain(String[]args){

FiletestFile=newFile("

c:

\\test"

System.out.println(testFile.getAbsolutePath()+"

try{

testFile.createNewFile();

catch(IOExceptione){

e.printStackTrace();

FiletestDir=newFile("

\\a\\b\\c"

System.out.println(testDir.getAbsolutePath()+"

+testDir.exists());

testDir.mkdirs();

importjava.util.*;

publicclassHashMapDemo{

publicstaticvoidmain(String[]args){

HashMap<

Integer,String>

map=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);

get:

+map.get

(2));

map.put(5,null);

+map.get(null));

Collection<

String>

coll=map.values();

System.out.println(coll);

publicclassHashMapDemo2{

//LinkedHashMap<

map=newLinkedHashMap<

//TreeMap<

map=newTreeMap<

Iterator<

Integer>

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

while(it.hasNext()){

Integeri=(Integer)it.next();

System.out.println(i+"

:

+map.get(i));

}

packagecn.edu.hncj;

classHashMapDemo1{

publicstaticvoidmain(Stringargs[]){

HashMaphm=newHashMap();

hm.put("

John"

newDouble(34.34));

Tom"

newDouble(23.22));

Jane"

newDouble(78.00));

Smith"

newDouble(99.22));

Rose"

newDouble(-19.88));

Iterator<

it=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