问什么一直看我这个图片
欢迎加入 xiaozhi 大家族
首页
推荐
百度一下
腾讯视频
Search
1
小米手机安装CA证书 MIUI13 Android 12可用
540 阅读
2
欢迎家人
226 阅读
3
2020.09.01 HTML 笔记
214 阅读
4
微信公众号推送早安问候以及天气预报 尾部附源码下载链接
200 阅读
5
MP代码生成器
176 阅读
默认分类
HTML初学日记
Java 笔记
小智的生活日记
Java 实用技巧
java面试经典问题
登录
Search
标签搜索
java基础
HTML初学记录
java分享
java抛错
小智
累计撰写
76
篇文章
累计收到
2
条评论
今日撰写
0
篇文章
首页
栏目
默认分类
HTML初学日记
Java 笔记
小智的生活日记
Java 实用技巧
java面试经典问题
页面
推荐
百度一下
腾讯视频
用户登录
登录
搜索到
76
篇与
的结果
2020-11-06
java集合|遍历HashMap的四种方法
public class HashMapStudy { public static void main(String[] args) { //一般来说,最好初始化一下, 小于12的就不要初始化了 // 默认的就是16,因为加载因子是0.75,也就是到16*0.75=12的时候会扩容 Map<String, String> map = new HashMap<>(3); map.put("welcome","to"); map.put("java","study"); map.put("wechat","best396975802"); //遍历方法1: 先遍历key , 再取出value System.out.println("遍历方法1: 先遍历key , 再取出value"); for (String key : map.keySet()) { System.out.println("key is "+key); System.out.println("value is "+ map.get(key)); } //遍历方法2: 直接遍历value System.out.println("遍历方法2: 直接遍历value"); for (String value : map.values()) { System.out.println("value is "+value); } //遍历方法3: 通过遍历entry来取Key和value,推荐的方法!!! System.out.println("遍历方法3: 通过遍历entry来取Key和value,推荐的方法!!!"); for (Map.Entry<String, String> entry : map.entrySet()) { System.out.println("key is "+entry.getKey()); System.out.println("value is "+ entry.getValue()); } //遍历方法4: 通过forEach方法直接遍历key和value System.out.println("遍历方法4: 通过forEach方法直接遍历"); map.forEach((key,value)->{ System.out.println("key is "+ key); System.out.println("value is "+ value); }); } }
2020年11月06日
16 阅读
0 评论
0 点赞
2020-11-06
java集合|遍历HashMap的四种方法
public class HashMapStudy { public static void main(String[] args) { //一般来说,最好初始化一下, 小于12的就不要初始化了 // 默认的就是16,因为加载因子是0.75,也就是到16*0.75=12的时候会扩容 Map<String, String> map = new HashMap<>(3); map.put("welcome","to"); map.put("java","study"); map.put("wechat","best396975802"); //遍历方法1: 先遍历key , 再取出value System.out.println("遍历方法1: 先遍历key , 再取出value"); for (String key : map.keySet()) { System.out.println("key is "+key); System.out.println("value is "+ map.get(key)); } //遍历方法2: 直接遍历value System.out.println("遍历方法2: 直接遍历value"); for (String value : map.values()) { System.out.println("value is "+value); } //遍历方法3: 通过遍历entry来取Key和value,推荐的方法!!! System.out.println("遍历方法3: 通过遍历entry来取Key和value,推荐的方法!!!"); for (Map.Entry<String, String> entry : map.entrySet()) { System.out.println("key is "+entry.getKey()); System.out.println("value is "+ entry.getValue()); } //遍历方法4: 通过forEach方法直接遍历key和value System.out.println("遍历方法4: 通过forEach方法直接遍历"); map.forEach((key,value)->{ System.out.println("key is "+ key); System.out.println("value is "+ value); }); } }
2020年11月06日
13 阅读
0 评论
0 点赞
2020-11-06
判断是否为文件夹 打印文件里边的东西
/** * 遍历文件夹 * @param file File file = new File("路径"); */ public static void getAllFile(File file) { System.out.println(file); //下边如果是问价夹跳出来 打印当前问价夹名称 File类中的listFiles()得到的是一个 File 类型的数组,返回的是该目录中的文件和目录。 File[] st = file.listFiles(); // 遍历数组 for (File f : st) { //判断问价夹是否为空 true不是空 递归 if (f.isDirectory()) { getAllFile(f); }else { //不是问价夹打印里边文件 System.out.println(f); } } }
2020年11月06日
18 阅读
0 评论
0 点赞
2020-11-05
修改密码 java清除txt文件 并且把HashMap数据写入进去
/** * 修改密码 * @param map HashMap数组 * @param username 用户名 要修改他的密码 */ public static void revisePwd(HashMap<String ,String> map,String username) { Scanner scanner = new Scanner(System.in); //看他传入的用户名在HashMap有没有存在 if(map.containsKey(username)) { System.out.println("请输入需要修改密码"); String pwd = scanner.next(); //判断他的密码和他里边的是否相等 if(pwd.equals(map.get(pwd))) { System.out.println("请勿修改重复密码"); }else { map.put(username, pwd); System.out.println("修改成功"); } } try { //读取文件 FileWriter fwr = new FileWriter("E:/ceshi/guanli/users.txt"); //将读取的文件清空 fwr.write(""); //遍历hashMap for(Map.Entry<String, String> arr : map.entrySet()) { //读取一行 PrintWriter pwr = new PrintWriter(fwr); //写入 一行 pwr.println(arr.getKey() +" "+ arr.getValue()); //垃圾回收 pwr.flush(); } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
2020年11月05日
9 阅读
0 评论
0 点赞
2020-11-04
异常 流
Day-24 异常 流Throwable 父类Exception 可以被处理 级别低 程序不终止Error 没有办法被处理 程序终止流 Stream输入流 输出流 字节流 字符流阻塞流 同步非阻塞流 异步非阻塞流I OI: 字节流 字符流读取一个字符FileReader reader = new FileReader("D:///.");读一个字符 int c = reader.read() (char)c 类型强转字符读取一行每次读取一个字符串FileReader reader = new FileReader("D:///.");BufferedReader br = new BufferedReader(reader); 读取一行的字符串 readerbr.readLine(); 读取一行将字节转换字符new IuputStreamReader() 也是一个流 将字节转换字符BufferedReader br = new BufferedReader(new IuputStreamReader(System.in));拼接两个文件 放在一个数组里边buf 键盘录入的东西 5从第五个值开始放 一共放十个值 reader.read(buf, 5, 10);输出流一次录取一行 必须写换行一次录取一行打印输出流 自动换行 PrintWriterFileWriter writer = new FileWriter("E:/ceshi/zx.txt"); //打印输出流 PrintWriter pw = new PrintWriter(writer); Scanner scanner = new Scanner(System.in); String str = ""; while (!(str = scanner.nextLine()).equals("bye")) { pw.print(str); } pw.flush();复制文件/** * 复制文件夹 */ public static void copy(String str , String str1) { FileReader reader = null; FileWriter writer = null; try { //读取文件 reader = new FileReader(str); //将每次读取读取一个转换成 读取一行 BufferedReader br = new BufferedReader(reader); //要复制的地方 writer = new FileWriter(str1); //没次写入一行 PrintWriter pw = new PrintWriter(writer); String st; while((st = br.readLine()) != null) { //写入一行换行 pw.println(st); } //冲一下 pw.flush(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); }finally { //释放资源 try { reader.close(); writer.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
2020年11月04日
18 阅读
0 评论
0 点赞
1
...
10
11
12
...
16