![](https://img-blog.csdnimg.cn/20201014180756928.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
常用类
常用类
反方向的钟c
一星程序员
展开
-
[常用类]使用Comparator实现定制排序
/* Comparator接口的使用:定制排序 1.背景: 当元素的类型没有实现java.lang.Comparable接口而又不方便修改代码,或者实现了 java.lang.Comparable接口的排序规则不适合当前的操作,那么可以考虑使用Comparator的对象来排序 2.重写compare(Object o1,Object o2)方法,比较o1和o2的大小: 如果方法返回正整数,则表示o1大于o2; 返回负整数,表示o1小于o2; ..原创 2022-04-26 12:46:28 · 218 阅读 · 0 评论 -
[常用类]自定义类实现Comparable自然排序
自定义商品类:public class Goods implements Comparable{ private String name; private double price; public Goods(){ } public Goods(String name, double price) { this.name = name; this.price = price; } public String原创 2022-04-26 10:48:00 · 323 阅读 · 0 评论 -
[常用类]DateTimeFormatter的使用
/* DateTimeFormatter:格式化或解析日期、时间 类似于SimpleDateFormat */ @Test public void test3(){ //方式一:预定义的标准格式 如: //ISO_LOCAL_DATE_TIME;ISO_LOCAL_DATE;ISO_LOCAL_TIME DateTimeFormatter formatter = DateTimeFormatter.ISO_..原创 2022-04-25 15:33:28 · 2795 阅读 · 0 评论 -
[常用类]Instant类的使用
/* Instant的使用 类似于java.util.Date类 */ @Test public void test2(){ //now():获取本初子午线对应的标准时间 Instant instant = Instant.now(); System.out.println(instant);//2022-04-25T05:56:58.562637400Z //添加时间的偏移量 O..原创 2022-04-25 14:32:00 · 634 阅读 · 0 评论 -
[常用类]LocalDate、LocalTime、LocalDateTime的使用
/* LocalDate、LocalTime、LocalDateTime 的使用 说明: 1.LocalDateTime相较于LocalDate、LocalTime,使用频率要高 2.类似于Calendar */ @Test public void test1(){ //now():获取当前的日期、时间、日期+时间 LocalDate localDate = LocalDate.now()...原创 2022-04-25 12:01:50 · 253 阅读 · 2 评论 -
[常用类]Calendar日历类的使用
/* Calendar日历类(抽象类)的使用 */ @Test public void testCalendar(){ //1.实例化 //方式一:创建其子类(GregorianCalendar)的对象 //方式二:调用其静态方法getInstance() Calendar calendar = Calendar.getInstance(); System.out.println(calen..原创 2022-04-25 11:04:44 · 204 阅读 · 0 评论 -
[常用类]SimpleDateFormat的使用
public class DateTimeTest1 { /* SimpleDateFormat的使用: SimpleDateFormat对日期Date类的格式化和解析 1. 两个操作: 1.1 格式化:日期 ---> 字符串 1.2 解析:格式化的逆过程,字符串 ---> 日期 2.SimpleDateFormat的实例化 */ @Test public void testSimpleDateFormat() t.原创 2022-04-25 10:09:41 · 143 阅读 · 0 评论 -
[常用类]Java中两个Date类的使用
public class DateTimeTest { //1.System类中的currentTimeMillis() @Test public void test1(){ long time = System.currentTimeMillis(); //返回当前时间与1970年1月1日0时0分0秒之间以毫秒为单位的时间差 //称为时间戳 System.out.println(time); } /.原创 2022-04-24 12:24:09 · 197 阅读 · 0 评论 -
[常用类]String、StringBuffer、StringBuilder效率对比
/* 对比String、StringBuffer、StringBuilder三者的效率: 从高到低排列:StringBuilder > StringBuffer > String */ @Test public void test3(){ //初始设置 long startTime = 0L; long endTime = 0L; String text = ""; ..原创 2022-04-24 10:21:17 · 1279 阅读 · 0 评论 -
[常用类]StringBuffer中的常用方法
/* StringBuffer的常用方法 StringBuffer append(xxx): 提供了很多的append()方法,用于进行字符串拼接 StringBuffer delete(int start,int end): 删除指定位置的内容 StringBuffer replace(int start,int end,String str): 把[start,end]位置替换为str StringBuffer insert(int offset,xxx)...原创 2022-04-24 09:58:01 · 190 阅读 · 0 评论 -
[常用类]StringBuffer的源码分析
public class StringBufferBuilderTest { /* String、StringBuffer、StringBuilder三者的异同? String:不可变的字符序列:底层使用char[]存储 StringBuffer:可变的字符序列:线程安全的,效率偏低;底层使用char[]存储 StringBuilder:可变的字符序列:jdk5.0新增的,线程不安全的,效率偏高;底层使用char[]存储 源码分析: String s原创 2022-04-23 23:53:28 · 336 阅读 · 0 评论 -
[常用类]String类与其他结构之间的转换
public class StringTest1 { /* String 与基本数据类型、包装类之间的转换 String ---> 基本数据类型、包装类:调用包装类的静态方法:parseXxx(str) 基本数据类型、包装类 ---> String:调用String重载的valueOf(xxx) */ @Test public void test1(){ String str1 = "123"; int .原创 2022-04-23 12:41:06 · 151 阅读 · 0 评论 -
[常用类]String的常用方法
-int length():返回字符串的长度: return value.length-char charAt(int index):返回某索引处的字符: return value[index]-boolean isEmpty():判断是否是空字符串: return value.length == 0-String toLowerCase():使用默认语言环境,将String中的所有字符转换为小写-String toUpperCase():使用默认语言环境,将String中的所有字符转换为大写-.原创 2022-04-23 08:29:08 · 76 阅读 · 0 评论 -
[常用类]String不同拼接操作的对比
/* 结论: 1. 常量与常量的拼接结果在常量池,且常量池中不会存在相同内容的常量 2. 只要其中有一个是变量,结果就在堆中 3. 如果拼接的结果调用intern()方法,返回值就在常量池中 */ @Test public void test3(){ String s1 = "JavaEE"; String s2 = "hadoop"; String s3 = "JavaEEhadoop"; String s4 =.原创 2022-04-22 16:08:51 · 48 阅读 · 0 评论 -
[常用类]理解String的不可变性及不同实例化方式的对比
public class StringTest { /* String:字符串,使用一对""引起来表示 1.String声明为final的,不可被继承 2.String实现了Serializable接口:表示字符串是支持序列化的 实现了Comparable接口:表示String可以比较大小 3.String内部定义了final char[] value用于存储字符串数据 4.String代表不可变的字符序列 简称:不可变性 .原创 2022-04-22 15:12:21 · 69 阅读 · 0 评论