java map统计学生名单_Java含自己的总结:集合,学生,遍历,ArrayList,Set,Map,泛型,班级,发牌—诗书画唱...

声明一个ArrayList,存储一条学生信息,内容为  1    张三   22    男,将信息进行遍历出来9d31ae3d18519b946c7362fe47d44d97.png

package list;

import java.util.ArrayList;

import java.util.Iterator;

public class student{

public static void main(String[] args) {

ArrayList jiHe = new ArrayList();

xueSheng xueSheng1 = new xueSheng(1,"张三",22,"男");

jiHe.add(xueSheng1);

for (int i = 0; i < jiHe.size(); i++) {

System.out.println(jiHe.get(i).toString());

}

}

}class xueSheng{

int bianhao;String name;int age;String sex;

public xueSheng(int bianhao, String name, int age, String sex) {

super();

this.bianhao = bianhao;

this.name = name;

this.age = age;

this.sex = sex;

}

@Override

public String toString() {

return "xueSheng [bianhao=" + bianhao + ", name=" + name + ", age="

+ age + ", sex=" + sex + "]";

}

}7fbd4307573b1da49517e2bcf27ebd20.png

f0afb094a5d1bae2ac026bd2514e9ff3.png

声明一个学生类,包含编号,名称,年龄,和性别属性,

实例化5名学生对象,将其保存在Set集合中,设置Set集合的泛型为SetXueSheng,遍历该Set集合

619fd78350a4c5691f499b79853968b2.png

616df6bdfef2808123c24fd24e3866a6.png

528ffb8dd454e730e3f38e538322147b.png

package list;

import java.util.*;

import java.util.Map.Entry;

public class set {

public static void main(String[] args) {

HashSet jiHe=new HashSet();

SetXueSheng duiXiang1=new SetXueSheng(1,"诗书三连",18,"男");

SetXueSheng duiXiang2=new SetXueSheng(2,"画唱点赞",19,"男");

SetXueSheng duiXiang3=new SetXueSheng(3,"诗书关注",20,"男");

SetXueSheng duiXiang4=new SetXueSheng(4,"画唱收藏",21,"男");

SetXueSheng duiXiang5=new SetXueSheng(5,"诗书画唱",22,"男");

jiHe.add(duiXiang1);

//第一个都要先放到集合中,之后才用Collections.addAll的方法。

//自己总结的语法:Collections.addAll(集合名,对象名1,对象名2,......)

Collections.addAll(jiHe,duiXiang2,duiXiang3,duiXiang4,duiXiang5);

for(SetXueSheng i:jiHe){

System.out.println(i);

}

}

}

class SetXueSheng{

public int bianhao;

public String name;

public int age;

public String sex;

public SetXueSheng(int bianhao, String name, int age, String sex) {

//super();可写可不写,因为没写父类,所以super();没作用,也没影响

this.bianhao = bianhao;

this.name = name;

this.age = age;

this.sex = sex;

}

@Override

public String toString() {

return "SetXueSheng [bianhao=" + bianhao

+ ", name=" + name + ", age="

+ age + ", sex=" + sex + "]";

}

}

8d6850d466e7b65c7a051af82fddcd40.png

51011afe0a5047aef02c77a253dcaa18.png

声明一个Map集合,设置泛型键为String,值为学生类,

将题2中的学生类保存在Map集合中,遍历该Map集合

package list;

import java.util.*;

import java.util.Map.Entry;

public class map {

public static void main(String[] args) {

Map MapJiHe=

new HashMap();

//自己总结的语法:Map 集合名=

//new HashMap();

studentMapClass duiXiang1=new studentMapClass(1,"诗书画唱",19,"男");

studentMapClass duiXiang2=new studentMapClass(2,"三连",20,"男");

studentMapClass duiXiang3=new studentMapClass(3,"关注",21,"男");

studentMapClass duiXiang4=new studentMapClass(4,"收藏",22,"男");

studentMapClass duiXiang5=new studentMapClass(5,"宝藏",23,"男");

//集合名.put(键(对应的数据类型的具体数据),值(对象名等));

MapJiHe.put("1",duiXiang1);MapJiHe.put("2",duiXiang2);

MapJiHe.put("3",duiXiang3);

MapJiHe.put("4",duiXiang4);MapJiHe.put("5",duiXiang5);

Iterator> dieDaiQi

=MapJiHe.entrySet().iterator();

//iterator

//[词典]【计】迭代器,迭代程序;

//Iterator(迭代器)是一个接口,它的作用就是遍历容器的所有元素。

//Iterator iter = list.iterator(); // 注意iterator,首字母小写

while(dieDaiQi.hasNext()){

Entry rongQi

=dieDaiQi.next();

//entry英[ˈentri]

//美[ˈentri]

//n.进入(指行动); 进入(指权利等); 参与,加入(指权利、机会);

System.out.println("键为"+rongQi.getKey()

+";值为"+rongQi.getValue());

}

}

}

class studentMapClass{

public int bianhao;

public String name;

public int age;

public String sex;

public studentMapClass(int bianhao,

String name, int age, String sex) {

//super();

this.bianhao = bianhao;

this.name = name;

this.age = age;

this.sex = sex;

}

@Override

public String toString() {

return "studentMapClass [bianhao=" + bianhao + ", name=" + name

+ ", age=" + age + ", sex=" + sex + "]";

}

}

10939b2e9a5a55f1e1d737bc97adf150.png

3bd0aa7784652ab0eb48dcdbeec7c13c.png

声明个map集合,设置键为班级名称String,值为每个班级的所有学生信息ArrayList,用来存储各个班级的学生信息,存储3个班级的学生信息,并遍历该map集合

7a5a9d4639b8493c0f240ca53f17c4ed.png

package list;

import java.util.*;

import java.util.Map.Entry;

public class mapArrayList {

public static void main(String[] args) {

//可以用"//————————"来当分割线,分层,更容易看懂等

//自己的总结:先声明一个HashMap集合

//再声明3个ArrayList集合,最后用上

//HashMap集合名.put(键(这里声明为String的内容),ArrayList集合名);

HashMap> HashMapJiHe

=new HashMap>();

//————————————————————————————————————————————————————————

ArrayList ArrayListJiHe1

=new ArrayList();//X班

studentMapArrayListClass duiXiang1=

new studentMapArrayListClass(1, "双笙",18,"女");

studentMapArrayListClass duiXiang2=

new studentMapArrayListClass(2, "就是哈比",18,"女");

studentMapArrayListClass duiXiang3=

new studentMapArrayListClass(3, "诺鸽鸽",18,"女");

ArrayListJiHe1.add(duiXiang1);ArrayListJiHe1.add(duiXiang2);

ArrayListJiHe1.add(duiXiang3);

//——————————————————————————————————————————————————————————————————

ArrayList ArrayListJiHe2

=new ArrayList();//XX班

studentMapArrayListClass duiXiang11=

new studentMapArrayListClass(11, "封茗囧茵",18,"女");

studentMapArrayListClass duiXiang22=

new studentMapArrayListClass(22, "等人",18,"男");

studentMapArrayListClass duiXiang33=

new studentMapArrayListClass(33, "都会",18,"男");

ArrayListJiHe2.add(duiXiang11);

ArrayListJiHe2.add(duiXiang22);ArrayListJiHe2.add(duiXiang33);

//————————————————————————————————————————————————————————————————

ArrayList ArrayListJiHe3

=new ArrayList();//XXX班

studentMapArrayListClass duiXiang111=

new studentMapArrayListClass(111, "未来成为",18,"男");

studentMapArrayListClass duiXiang222=

new studentMapArrayListClass(222, "我诗书",18,"男");

studentMapArrayListClass duiXiang333=

new studentMapArrayListClass(333, "画唱后宫",18,"男");

ArrayListJiHe3.add(duiXiang111);

ArrayListJiHe3.add(duiXiang222);

ArrayListJiHe3.add(duiXiang333);

//——————————————————————————————————————————————————

HashMapJiHe.put("X班",ArrayListJiHe1);HashMapJiHe.put("XX班",ArrayListJiHe2);

HashMapJiHe.put("XXX班",ArrayListJiHe3);

//————————————————————————————————————————————————

//声明Iterator的自己总结的语法

//:Iterator>> Iterator名

//= HashMap集合名.entrySet().iterator();

//

//多找到,想到并且记录等

//自己和别人容易理解,熟悉的,

//将其比作自己和别人容易理解,熟悉的。这样可以更好的记忆,理解,

//认为懂了和获得我们大多人定义的真正的懂了。很多东西等都是被定义的,本身并不存在

//所有的班级和学生等的内容会因为声明了Iterator,而被装到Iterator里面,

//

//Iterator等就像一个水杯,内容就像水,声明Iterator就像把水倒进水杯中

//而用hasNext()等来遍历Iterator就像把水从水杯中到倒出来

Iterator>> allneiRongIteratorName

= HashMapJiHe.entrySet().iterator();

//自己总结的遍历Iterator的语法:

//while(Iterator名.hasNext()){

//}

while(allneiRongIteratorName.hasNext()){

//声明一个Entry的自己总结的语法:

//Entry> Entry名

//=Iterator名.next();

Entry> EntryName

=allneiRongIteratorName.next();

//用.next()得到下一条String类型的数据

System.out.println("班级为"+EntryName.getKey());

System.out.println("具体的学生信息为");

//这里情形的自己总结的for遍历集合的语法:

//Entry名.getValue()这里为ArrayList集合

//for(类名 要打印的内容名:集合或集合名){

//System.out.println(要打印的内容名);

//}

for(studentMapArrayListClass valueNeiRong:EntryName.getValue()){

System.out.println(valueNeiRong);

}

}

}

}

//——————————————————————————————————————

class studentMapArrayListClass{

public int bianhao;

public String name;

public int age;

public String sex;

public studentMapArrayListClass(int bianhao, String name, int age,

String sex) {

super();

this.bianhao = bianhao;

this.name = name;

this.age = age;

this.sex = sex;

}

@Override

public String toString() {

return "studentMapClass [bianhao=" + bianhao + ", name=" + name

+ ", age=" + age + ", sex=" + sex + "]";

}

}

171efdbf991683c279397cc52a3c93c6.png

e1c23bb6705e4c773ca310a5ebe6720b.png

制作扑克牌发牌案例

5339d50eca84bad9593f4cfb43151f3d.png

package list;

import java.util.ArrayList;

import java.util.HashMap;

import java.util.Random;

public class douDiZhuFaPaiTi5 {

public static void main(String[] args) {

String[] Stringchucundepai = new String[] { "♥A", "♥2", "♥3", "♥4",

"♥5", "♥6", "♥7", "♥8", "♥9", "♥10", "♥J", "♥Q", "♥K", "♠A",

"♠2", "♠3", "♠4", "♠5", "♠6", "♠7", "♠8", "♠9", "♠10", "♠J",

"♠Q", "♠K", "♦A", "♦2", "♦3", "♦4", "♦5", "♦6", "♦7", "♦8",

"♦9", "♦10", "♦J", "♦Q", "♦K", "♣A", "♣2", "♣3", "♣4", "♣5",

"♣6", "♣7", "♣8", "♣9", "♣10", "♣J", "♣Q", "♣K" };

HashMap HSchucundejiadepai = new HashMap<>();

HashMap HSchucundeyidepai = new HashMap<>();

HashMap HSchucundebingdepai = new HashMap<>();

ArrayList yongALchucundeshuju = new ArrayList();

for (int i = 0; i < Stringchucundepai.length; i++) {

yongALchucundeshuju.add(Stringchucundepai[i]);

}

yongALchucundeshuju.add("大王");

yongALchucundeshuju.add("小王");

Random suijishu = new Random();

String fangzidawangxiaowangchongfu = null;

for (int k = 0; k < 100; k++) {

int zongpaishu = yongALchucundeshuju.size();

int yongRandomdedaodesuijishu1 = suijishu.nextInt(zongpaishu);

int yongRandomdedaodesuijishu2 = suijishu.nextInt(zongpaishu);

if (yongRandomdedaodesuijishu1 == yongRandomdedaodesuijishu2)

continue;

{

fangzidawangxiaowangchongfu = yongALchucundeshuju

.get(yongRandomdedaodesuijishu1);

yongALchucundeshuju.set(yongRandomdedaodesuijishu1,

yongALchucundeshuju.get(yongRandomdedaodesuijishu2));

yongALchucundeshuju.set(yongRandomdedaodesuijishu2,

fangzidawangxiaowangchongfu);

}

}

ArrayList yongALchucundejiadepai = new ArrayList();

ArrayList yongALchucundeyidedepai = new ArrayList();

ArrayList yongALchucundebingdepai = new ArrayList();

ArrayList yongALchucundedipai = new ArrayList();

for (int i = 0; i < yongALchucundeshuju.size(); i++) {

if (i >= yongALchucundeshuju.size() - 3) {

yongALchucundedipai.add(yongALchucundeshuju.get(i));

} else if (i % 3 == 0) {

yongALchucundejiadepai.add(yongALchucundeshuju.get(i));

} else if (i % 3 == 1) {

yongALchucundeyidedepai.add(yongALchucundeshuju.get(i));

} else if (i % 3 == 2) {

yongALchucundebingdepai.add(yongALchucundeshuju.get(i));

}

}

System.out.println("底牌:" + yongALchucundedipai);

System.out.println("甲被发到的牌:" + yongALchucundejiadepai);

System.out.println("乙被发到的牌:" + yongALchucundeyidedepai);

System.out.println("丙被发到的牌:" + yongALchucundebingdepai);

}

}

85d087af984556fc94dc95599e9d0040.png

44de2239c496f0edd6ec505f9132b3a5.png

1835a55f5b60778abfb8fa23eea1c5b9.png

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/441361.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

java生成world文件_HelloWorld.java文件如何创建?

原创HelloWorld.java文件如何创建&#xff1f;编辑:小丸子 来源:PC下载网时间:2017-10-17 19:55:54相信各位刚接触JAVA的新人都希望尽快编写出自己的第一个程序,今天PC下载网小编和你一起学习HelloWorld程序1.首先我们先点击“开始”—然后是“所有程序”—在然后是“附件”—记…

wifisetting.java_Wifi 笔记 | 启动流程

csd&#xff1a;csdn_of_coder/article/details/51541094aosp: Android OAndroid网络各个模式中&#xff0c;Wifi应该是目前最常用的一种网络方式了&#xff1b;下面就简单介绍下Android中Wifi的启动流程。当我在Setting菜单里点击打开Wifi时&#xff0c;调用的入口函数是WifiM…

java 调用动态链接库_JAVA技巧:JNative调用动态链接库问题(SOS)

动态链接库的方法如下&#xff1a;__declspec(dllexport) ret __stdcall rLachTran(const char *pc_trancode,const char *pc_clicode,const char *pc_orgcode,const char *pc_ttycode,const int i_brandid,const char *pc_reqstamp,const int i_reqseqno,const char *pc_svrip…

【POJ - 3347 】Kadj Squares (计算几何,思维 或 扫描线)

题干&#xff1a; In this problem, you are given a sequence S1, S2, ..., Sn of squares of different sizes. The sides of the squares are integer numbers. We locate the squares on the positive x-y quarter of the plane, such that their sides make 45 degrees w…

按钮开关java代码,Android自定义实现开关按钮代码

我们在应用中经常看到一些选择开关状态的配置文件&#xff0c;做项目的时候用的是android的Switch控件&#xff0c;但是感觉好丑的样子子个人认为还是自定义的比较好&#xff0c;先上个效果图&#xff1a;实现过程&#xff1a;1.准备开关不同状态的两张图片放入drawable中。2.x…

*【CodeForces - 202C 】Clear Symmetry (思维,找规律,特判)

题干&#xff1a; Consider some square matrix A with side n consisting of zeros and ones. There are nrows numbered from 1 to n from top to bottom and n columns numbered from 1 to n from left to right in this matrix. Well denote the element of the matrix wh…

*【CodeForces - 768B】Code For 1 (分治策略,模拟二分思想,模拟线段树思想)

题干&#xff1a; Jon fought bravely to rescue the wildlings who were attacked by the white-walkers at Hardhome. On his arrival, Sam tells him that he wants to go to Oldtown to train at the Citadel to become a maester, so he can return and take the decease…

matlab 自适应噪声对消,基于Matlab的RLS自适应语音噪声对消系统的设计与实现

基于Matlab 的R LS 自适应语音噪声对消系统的设计与实现①肖 哲(湖南工业大学科技学院, 湖南株洲 412008)摘 要:自适应信号处理的理论和技术经过40多年的发展和完善,已逐渐成为人们常用的语音去噪技术.而Matlab 的出现又为其提供了更为方便快捷的方法来对语音信号进行消噪处…

贪心算法 -- 最小延迟调度

转自&#xff1a;https://blog.csdn.net/bqw18744018044/article/details/80285414 总结&#xff1a; 首先&#xff0c;证明贪心的时候交换论证是万能的&#xff01;其次&#xff0c;这一点如果要满足&#xff0c;也就是&#xff0c;如果你要用交换论证法&#xff0c;那么首先…

apache2+支持php7,Ubuntu14.04下配置PHP7.0+Apache2+Mysql5.7

Apache步骤一&#xff1a;安装apacheronyaoubuntu:~$ sudo apt install apache2安装好后&#xff0c;在浏览器上输入localhost(服务器端&#xff0c;请输入你的IP地址)&#xff0c;回车就会看到&#xff1a;PHP7.0步骤二&#xff1a;Ubuntu14.04下的默认源是PHP5.0&#xff0c;…

【CodeForces - 1051D】Bicolorings (dp,类似状压dp)

题干&#xff1a; You are given a grid, consisting of 22 rows and nn columns. Each cell of this grid should be colored either black or white. Two cells are considered neighbours if they have a common border and share the same color. Two cells AA and BB be…

【 HDU - 1796】How many integers can you find (容斥原理,二进制枚举或者dfs)

题干&#xff1a; Now you get a number N, and a M-integers set, you should find out how many integers which are small than N, that they can divided exactly by any integers in the set. For example, N12, and M-integer set is {2,3}, so there is another set {2,…

【CodeForces - 1027B 】Numbers on the Chessboard (没有营养的找规律题,无聊题)

题干&#xff1a; You are given a chessboard of size nnnn. It is filled with numbers from 11 to n2n2 in the following way: the first ⌈n22⌉⌈n22⌉ numbers from 11 to ⌈n22⌉⌈n22⌉ are written in the cells with even sum of coordinates from left to right f…

【CodeForces - 1060C】Maximum Subrectangle (思维,预处理前缀和,dp,枚举长度)

题干&#xff1a; You are given two arrays aa and bb of positive integers, with length nn and mmrespectively. Let cc be an nmnm matrix, where ci,jai⋅bjci,jai⋅bj. You need to find a subrectangle of the matrix cc such that the sum of its elements is at m…

【Codeforces 631C 】Report(单调栈,思维模拟)

题干&#xff1a; Each month Blake gets the report containing main economic indicators of the company "Blake Technologies". There are n commodities produced by the company. For each of them there is exactly one integer in the final report, that d…

【CodeForces - 215A】Bicycle Chain (水题)

题干&#xff1a; Vasyas bicycle chain drive consists of two parts: n stars are attached to the pedal axle, m stars are attached to the rear wheel axle. The chain helps to rotate the rear wheel by transmitting the pedal rotation. We know that the i-th sta…

ubuntu 在线安装php,ubuntu在线安装LNMP

一直以来个人安装lamp环境都是源码编译的&#xff0c;这个过程呢其实也要去经历的&#xff0c;但是毕竟占用时间久&#xff0c;有些时候在做一些测试环境的时候&#xff0c;可以在线安装比较快源码编译nginx可看往期&#xff1a;Nginx的安装对于lnmp的在线安装&#xff0c;如下…

【CodeForces - 215B 】Olympic Medal (数学,公式推导)

题干&#xff1a; The World Programming Olympics Medal is a metal disk, consisting of two parts: the first part is a ring with outer radius of r1 cm, inner radius of r2 cm, (0 < r2 < r1)made of metal with density p1 g/cm3. The second part is an i…

【CodeForces - 215C 】Crosses (思维,图形题)

题干&#xff1a; There is a board with a grid consisting of n rows and m columns, the rows are numbered from 1 from top to bottom and the columns are numbered from 1 from left to right. In this grid we will denote the cell that lies on row number i and co…

Scaffold php,GitHub - yiiplus/scaffold: scaffold是一个基于Yii2高级项目模版工程化实现的应用程序...

Yii 2 Scaffold Project Kit易加-脚手架(scaffold)是一个基于Yii2高级项目模版工程化实现的应用程序&#xff0c;它将更加高效、规范和工程化的满足项目开发的需求。DIRECTORY STRUCTUREcommonconfig/ contains shared configurationsmail/ contains view files for e-mailsmod…