高性能Java
文章平均质量分 88
while(true){}
这个作者很懒,什么都没留下…
展开
-
单例模式的几种实现方式
1.普通实现 package com.shi.test; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; public class Example { //私有化成员对象,在类加载的时候进行初始化操作 private static final Example example = new Example(); //私有化构造器 private Example() {原创 2020-10-09 21:34:58 · 161 阅读 · 0 评论 -
使用Java的Stream流实现词频统计功能
1.使用分组和计数函数来实现词频统计 @Test public void test() throws IOException { //定义要加载的文件位置 String path = "word.txt"; //通过Files.lines获取字符流对象 Stream<String> stream = Files.lines(Path.of(path)); stream = stream.flatMap(原创 2020-08-23 10:12:01 · 1597 阅读 · 0 评论 -
构建Java对象遇到多个参数时的构建方式
1.此文章讨论在构建Java对象时遇到多参数问题(有些是非必须的)如何进行合理的构建。 2.遇到这种情况有三种处理方式: 重叠构造器: JavaBean模式 建造者(Builder)模式 创建的虚拟实体类为Book类,其中: //必需的参数 private String bookName; private float price; //以下为非必需的参数 private String authorName; private String bookPublishing; private String c原创 2020-08-13 23:11:26 · 1522 阅读 · 0 评论