欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

第一次写博客

程序员文章站 2022-08-11 14:18:39
今天是我第一次写博客,有很多不懂的,正在学习过程中。 说到学习,我现在也正处于学习Java的过程中,希望在旅途中能够遇见一起前进的伙伴。 现在的进度我就用代码表示吧,看博客的前辈们应该都了解!而且第一次写博客也不知道写什么合适,就用代码代替了,之后我慢慢了解吧。 当然,这些都是我的练习的代码,如果有 ......

今天是我第一次写博客,有很多不懂的,正在学习过程中。

说到学习,我现在也正处于学习java的过程中,希望在旅途中能够遇见一起前进的伙伴。

现在的进度我就用代码表示吧,看博客的前辈们应该都了解!而且第一次写博客也不知道写什么合适,就用代码代替了,之后我慢慢了解吧。

当然,这些都是我的练习的代码,如果有错或者什么地方需要修改希望各位不吝赐教

package java_01;
import java.util.hashmap;
import java.util.iterator;
import java.util.map;
import java.util.set;
//map集合是java中用于储存一对一一对应的键值对的容器
public class collectionmap {
public static void main(string[] args) {
// show01();
// show02();
// show03();
// show04();
show05();
}
public static void show01() {
//创建并添加元素
hashmap<string,string> hm = new hashmap<>();
hm.put("小绿","男");
hm.put("小红","男");
hm.put("小蓝","女");
system.out.println(hm);
}
public static void show02() {
//创建并添加元素
hashmap<string,string> hm = new hashmap<>();
hm.put("小绿","男");
hm.put("小红","男");
hm.put("小蓝","女");
//删除元素
hm.remove("小绿");
system.out.println(hm);
}
public static void show03() {
//创建并添加元素
hashmap<string,string> hm = new hashmap<>();
hm.put("小绿","男");
hm.put("小红","男");
hm.put("小蓝","女");
//判断是否包含某key值
boolean b=hm.containskey("小红");
system.out.println(b);
}
private static void show04(){
hashmap<string,string> hm = new hashmap<>();
hm.put("小绿","男");
hm.put("小红","男");
hm.put("小蓝","女");
//将hm集合中的key值存储到set集合中
set<string> se = hm.keyset();
//遍历
//迭代器
iterator<string> it = se.iterator();
while (it.hasnext()){
string str = it.next();
//hm.get(str)返回与key值(str)对应的value值
system.out.println(str+":"+hm.get(str));
}
system.out.println("*************");
//增强for循环
for (string str2:se) {
system.out.println(str2+":"+hm.get(str2));
}
}
private static void show05(){
hashmap<string,string> hm = new hashmap<>();
hm.put("小绿","男");
hm.put("小红","男");
hm.put("小蓝","女");
//把hm中的值作为enter对象存入set集合
set<map.entry<string, string>> se = hm.entryset();
//迭代遍历
iterator<map.entry<string, string>> it = se.iterator();
while (it.hasnext()){
map.entry<string, string> ne = it.next();
// system.out.println(ne);
//也可以分别获取
string key = ne.getkey();
string value = ne.getvalue();
system.out.println(key+"是"+value+"性");
}
}
}