首页 技术 正文
技术 2022年11月14日
0 收藏 312 点赞 2,408 浏览 2269 个字

第一题:

  

 import java.util.*; public class ListTest {     public static void main(String[] args) {         ArrayList<Integer> list = new ArrayList<Integer>();         for(int i=0;i<101;i++){             list.add(i);
}
System.out.println("原先的数据:\n"+list); list.remove(10); System.out.println("移除之后的数据:\n"+list);
}
}

运行的结果:

原先的数据:
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100]
移除之后的数据:
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100]

第二题:

  

 import java.util.*; public class SetList {     public static void main(String[] args) {         ArrayList<String> list = new ArrayList<>();
HashSet<String> set = new HashSet<String>();
TreeSet<String> set1 = new TreeSet<String>(); Collections.addAll(list, "A","a","c","C","a");
Collections.addAll(set, "A","a","c","C","a");
Collections.addAll(set1, "A","a","c","C","a"); System.out.println("list的数据:\t"+list);
System.out.println("set的数据:\t"+set);
System.out.println("set的数据:\t"+set1); }
}

运行的结果:

list的数据: [A, a, c, C, a]
set的数据:[c, A, C, a]
set的数据:[A, C, a, c]

第三题:

 import java.util.*; public class TestMap {     public static void main(String[] args) {         Emp e1 = new Emp("001","小赵");
Emp e2 = new Emp("002","小钱");
Emp e3 = new Emp("003","小孙");
Emp e4 = new Emp("004","小李");
Emp e5 = new Emp("005","小周");
Emp e6 = new Emp("006","小吴"); HashMap<String,String> m = new HashMap<String,String>(); m.put(e1.getId(), e1.getName());
m.put(e2.getId(), e2.getName());
m.put(e3.getId(), e3.getName());
m.put(e4.getId(), e4.getName());
m.put(e5.getId(), e5.getName());
m.put(e6.getId(), e6.getName()); System.out.println("原始的数据:\n"+m); m.remove("005"); System.out.println("移除之后的数据:\n"+m); }
}
class Emp{ private String id;
private String name;
public Emp(String id, String name) {
super();
this.id = id;
this.name = name;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
} }

运行的结果:

原始的数据:
{004=小李, 005=小周, 006=小吴, 001=小赵, 002=小钱, 003=小孙}
移除之后的数据:
{004=小李, 006=小吴, 001=小赵, 002=小钱, 003=小孙}

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,088
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,565
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,413
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,186
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,822
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,905