JAVASE基础类

ArrayListStudy
public class ArrayListStudy {
    public static void main(String[] args) {
        /*java.util;需要导包

         */
/*构造方法*/
        ArrayList<String> s1 = new ArrayList<>();//构造方法1;构造一个初始容量为10的容器;<泛型>只能使用引用数据类型,不可以加int等基本数据类型
/*成员方法*/
        s1.add("ABC");//集合的向末尾添加数据的方法
        s1.add(0,"666");//将数据添加到指定索引位置
        String a= s1.remove(0);//删除指定索引位置的数据;并返回删除的数据;
        boolean b=s1.remove("ABC");//删除对应数据的数据并返回布尔类型的值;只能删除第一个;
        String c=s1.set(0,"hello");//将指定索引位置的数据替换为指定数据;并返回修改的数据;
        String d= s1.get(0);//返回指定索引位置的数据
        int e=s1.size();//返回集合的长度
    }
}

============================================

Arrays
public class ArraysStudy {
    public static void main(String[] args) {
        /* Arrays.toString(arr);//打印数组元素;
        Arrays.sort(int[] a)//按照数字顺序排列指定的数组
        Arrays.binarySearch(int[] a, int key)//利用二分查找返回指定元素的索引*/
        /*成员方法*/
        int[] arr={1,2,3,4,5};
        System.out.println(Arrays.toString(arr));
        Arrays.sort( arr);//按照数字顺序排列指定的数组
        System.out.println(Arrays.toString(arr));//打印数组元素;
        System.out.println(Arrays.binarySearch(arr, 3));//利用二分查找返回指定元素的索引


    }
}

==========================================

BigDecimalStudt
public class BigDecimalStudt {
    public static void main(String[] args) {
        /*java.lang*/
/*构造方法*/
         BigDecimal bd1 = new BigDecimal(10.3);
         BigDecimal bd2 = new BigDecimal("0.3");//字符串构造可以提高精确度
/*成员方法*/
        /*public BigDecimal add(另一个BigDecimal对象)//加法
        public BigDecimal subtract (另一个BigDecimal对象)//减法
        public BigDecimal multiply (另一个BigDecimal对象)//乘法
        public BigDecimal divide (另一个BigDecimal对象)//除法
        public BigDecimal divide (另一个BigDecimal对象,精确几位,舍入模式)//除法*/
        System.out.println(bd1.add(bd2));
        System.out.println(bd1.subtract(bd2));
        System.out.println(bd1.multiply(bd2));
        System.out.println(bd1.divide(bd2));//除不尽会报错
        System.out.println(bd1.divide(bd2,2,BigDecimal.ROUND_UP));
        //ROUND_UP 进一法
        //ROUND_FLOOR 去尾法
        //ROUND_HALF_UP 四舍五入


    }
}

======================================

DataStudy
public class DataStudy {
    public static void main(String[] args) {
/* 类 日期类  Date
Date类构造方法
public Date()//分配一个 Date对象,并初始化,以便它代表它被分配的时间,精确到毫秒//当前时间
public Date(long date)//分配一个 Date对象,并将其初始化为表示从标准基准时间起指定的毫秒数//计算机原点加指定毫秒时间后的时间加8小时
常用方法
public long getTime()//获取的是日期对象从1970年1月1日 00:00:00到现在的毫秒值//System.currentTimeMillis();
public void setTime(long time)//设置时间,给的是毫秒值*/
        long s=System.currentTimeMillis();
/*构造方法*/
        Date date1 = new Date();
        Date date2 = new Date(3600L);
/*成员方法*/
        System.out.println(date1.getTime());//获取的是日期对象从1970年1月1日 00:00:00到现在的毫秒值
        date1.setTime(3600L);//设置时间,给的是毫秒值,修改时间为输入的时间

    }
}

===========================================

 DurationStudy
public class DurationStudy {
    public static void main(String[] args) {
      /*  public static Durationbetween(开始时间,结束时间)//计算两个“时间"的间隔
        public long toSeconds()//获得此时间间隔的秒
        public int toMillis()//获得此时间间隔的毫秒
        public int toNanos()//获得此时间间隔的纳秒*/
        LocalDateTime s1 = LocalDateTime.of(2022, 02, 03, 14, 25, 25);
        LocalDateTime s2 = LocalDateTime.of(2021, 02, 03, 14, 25, 25);
        System.out.println(Duration.between(s1, s2));
        System.out.println(Duration.between(s1, s2).toSeconds());
        System.out.println(Duration.between(s1, s2).toMillis());
        System.out.println(Duration.between(s1, s2).toNanos());
    }

}

=========================================

IntegerStudy
public class IntegerStudy {
    public static void main(String[] args) {
       /* 基本类型包装类(记忆)
        基本数据类型的包装类(数据类型首字母大写,两个例外)将基本类型封装成对象
        int  Integer
        char  Character*/
 /*       构造方法
public Integer(int   value)//根据 int 值创建 Integer 对象(过时)
public Integer(String s)//根据 String 值创建 Integer 对象(过时)
        public static Integer valueOf(int i)//返回表示指定的 int 值的 Integer   实例
        public static Integer valueOf(String s)//返回一个保存指定值的 Integer 对象 String
        parseInt()// int y = Integer.parseInt(s);String转换为int*/
/*  构造方法*/
        Integer s1=Integer.valueOf(456);
        Integer s2=Integer.valueOf("456");
        Integer s3=100;
        Integer s4=Integer.parseInt("100");
        System.out.println(s1);
        System.out.println(s2);
        System.out.println(s3);
        System.out.println(s4);
/*成员方法*/
        Integer.parseInt("456");//把int类型的字符串转为一个Integer类型的对象

    }
}

==========================================

LocalDateTimeStudy
public class LocalDateTimeStudy {
    public static void main(String[] args) {
       /* 类  LocalDateTime
        public LocalDate toLocalDate ()//转换成为一个LocalDate对象
        public LocalTime toLocalTime ()//转换成为一个LocalTime对象
        public int getYear()//获取年
        public int getMonthValue()//获取月份(1-12)
        public int getDayOfMonth()//获取月份中的第几天(1-31)
        public int getDayOfYear()//获取一年中的第几天(1-366)
        public DayOfWeek getDayOfWeek()//获取星期
        public int getMinute()//获取分钟
        public int getHour()//获取小时
        public String format (指定格式)//把一个LocalDateTime格式化成为一个字符串
        public LocalDateTime parse (准备解析的字符串, 解析格式)/把一个日期字符串解析成为一个LocalDateTime对象
        public static DateTimeFormatter ofPattern(String pattern)//使用指定的日期模板获取一个日期格式化器DateTimeFormatter对象
        public LocalDateTime plusYears (long years)//添加或者减去年
        public LocalDateTime plusMonths(long months)//添加或者减去月
        public LocalDateTime plusDays(long days)//添加或者减去日
        public java.time.LocalDateTime plusHours(long hours)//添加或者减去时
        public LocalDateTime plusMinutes(long minutes)//添加或者减去分
        public LocalDateTime plusSeconds(long seconds)//添加或者减去秒
        public LocalDateTime plusWeeks(long weeks)//添加或者减去周
        public LocalDateTime  minusYears (long years)//减去或者添加年
        public LocalDateTime  minusMonths(long months)//减去或者添加月
        public LocalDateTime minusDays(long days)//减去或者添加日
        public LocalDateTime minusHours(long hours)//减去或者添加时
        public LocalDateTime minusMinutes(long minutes)//减去或者添加分
        public LocalDateTime minusSeconds(long seconds)//减去或者添加秒
        public LocalDateTime minusWeeks(long weeks)//减去或者添加周
        public LocalDateTime withYear(int year)//直接修改年
        public LocalDateTime withMonth(int month)//直接修改月
        public LocalDateTime withDayOfMonth(int dayofmonth)//直接修改日期(一个月中的第几天)
        public LocalDateTime withDayOfYear(int dayOfYear)//直接修改日期(一年中的第几天)
        public LocalDateTime withHour(int hour)//直接修改小时
        public LocalDateTime withMinute(int minute)//直接修改分钟
        public LocalDateTime withSecond(int second)//直接修改秒
        public static LocalDateTime now()//获取当前系统时间
        public static LocalDateTime of  (年, 月 , 日, 时, 分, 秒)//使用指定年月日和时分秒初始化一个LocalDateTime对  yyyy年MM月dd日 HH时mm分ss秒*/
/*无构造方法*/
        LocalDateTime now = LocalDateTime.now();//相当于 Date date1 = new Date();
        System.out.println(now);
        LocalDateTime s2 = LocalDateTime.of(2022, 02, 03, 14, 25, 25);//相当于 Date date1 = new Date(long);
        System.out.println(s2);
        System.out.println(s2.getYear());//获取年


    }
}

==================================================

MathStudy
public class MathStudy {
    public static void main(String[] args) {
        /*java.lang
         没有构造方法,无法创建实例对象
abs()//返回参数的绝对值
ceil(double a)//返回大于或等于参数的最小double值,等于一个整数
floor(double a)//返回小于或等于参数的最大double值,等于一个整数
round(float a)//按照四舍五入返回最接近参数的int
max( a, b)//返回两个值中的较大值
min( a, b)//返回两个值     中的较小值
pow (double a,double b)//返回a的b次幂的值
random()//返回值为double的正值,[0.0,1.0)
         */
/*无构造方法,无法实例对象;类中的构造方法私有化,无法创建对象*/
/*成员方法*/
        int a=10;
        int b=6;
        double c=10.5;
        Math.abs(a);//返回参数的绝对值
        Math.ceil(c);//返回大于或等于参数的最小double值,等于一个整数
        Math.floor(c);//返回小于或等于参数的最大double值,等于一个整数
        Math.round(c);//按照四舍五入返回最接近参数的int
        Math.max(a,b);//返回两个值中的较大值
        Math.min(a,b);//返回两个值中的较小值
        Math.pow(a,b);//返回a的b次幂的值
        Math.random();//返回值为double的正值,[0.0,1.0)
    }
}

======================================

 ObjectsStudy
public class ObjectsStudy {
    public static void main(String[] args) {
       /* public static String toString(对象)//返回参数中对象的字符串表示形式。
        public static String toString(对象, 默认字符串)//如果对象为空返回默认字符串;返回对象的字符串表示形式。
        public static Boolean isNull(对象)//判断对象是否为空
        public static Boolean nonNull(对象)//判断对象是否不为空*/
        String s=null;
        String a=Objects.toString(s,"aaaa");
        Boolean result= Objects.isNull(s);
        Boolean result1=Objects.nonNull(s);

    }
}
/*类中to String 方法的重写*/
 /*重写toString方法的方式
         - 1. Alt + Insert 选择toString
         - 1. 在类的空白区域,右键 -> Generate -> 选择toString*/
 /*s1.equals(s2)//用于对象之间的比较,返回true和false的结果;不希望比较对象的地址值,想要结合对象属性进行比较的时候重写equals方法的方式。
         - 1. alt + insert  选择equals() and hashCode(),IntelliJ Default,一路next,finish即可
         - 1. 在类的空白区域,右键 -> Generate -> 选择equals() and hashCode(),后面的同上。*/

==========================================

 PeroidStudy
public class PeroidStudy {
    public static void main(String[] args) {
        /*类 Period 日期类
        public int getYears()//获得这段时间的年数
        public static Period between(开始时间,结束时间)//计算两个“时间"的间隔开始时间和结束时间对象为locaDate类型;
        public int getMonths()//public int getMonths()获得此期间的总月数
        public int getDays()//获得此期间的天数
        public long toTotalMonths()//获取此期间的总月数*/
        LocalDate s1 = LocalDate.of(2022, 02,23);
        LocalDate s2 = LocalDate.of(2022, 03 ,23
        );
        Period period = Period.between(s1, s2);
        System.out.println(period.getMonths());
        System.out.println(period.toTotalMonths());
    }
}

========================================

SimpleDateFormatStudy 
public class SimpleDateFormatStudy {
    public static void main(String[] args) throws ParseException {
       /* 类  SimpleDateFormat  日期类
       public final String formatr(Date date)//将日期转为当前SimpleDateFormat的格式
        public Date parse(String source)//从给定字符串的开始解析文本以生成日期
        public int getYear()//获取年
        public int getMonthValue()//获取月份(1-12)
        public int getDayOfMonth()//获取月份中的第几天(1-31)
        public int getDayOfYear()//获取一年中的第几天(1-366)
        public DayOfWeek getDayOfWeek()//获取星期
        public int getMinute()//获取分钟
        public int getHour()//获取小时*
        年 y 月 M 日 d 时 H 分  m 秒  s  --yyyy-MM-dd-HH-mm-ss  yyyy年MM月dd日HH时mm分ss秒
       */
/*构造方法*/
        //创建一个日期格式
        SimpleDateFormat s1 = new SimpleDateFormat("yyyy年MM月dd日HH时mm分ss秒");
        //需要使用当前时间
        Date date1 = new Date();
/*成员方法*/
        System.out.println(s1.format(date1));//2022年07月27日08时51分43秒;将日期转为当前SimpleDateFormat的格式
        String s="2022年07月27日08时51分43秒";
        System.out.println(s1.parse(s));//Wed Jul 27 08:51:43 CST 2022//将SimpleDateFormat的格式的日期转为系统日期格式


    }
}

==================================================

StringBudilderStudy
public class StringBudilderStudy {
    public static void main(String[] args) {
/*此类可提高字符串的工作效率
java.lang
大小可变,相等与一个可变字符串容器;
 */
/*构造方法*/
        StringBuilder s1=new StringBuilder();//构造方法1
        StringBuilder s2=new StringBuilder("abc");//构造方法2
/*成员方法*/
        StringBuilder a= s1.append("acb");//可以添加任意数据类型;可链式编程append().append().....
        StringBuilder b=s1.reverse();//将数据反转;
        int c=s1.length();//返回长度;
        String d=s1.toString();//转成String类型;




    }
}

==============================================

StringStudy
public class StringStudy {
    public static void main(String[] args) {
        //API(Application Programming Interface)
        /*
        class String(字符串)jvav.lang**不需要导包//字符串容量池
         */
/*构造方法*/
        String s1="abc";//构造方法1
        String s2=new String();//构造方法2
        char[] chs={'a','b','c'};
        String s3=new String(chs);//构造方法3,不是内存地址是个字符串;StringBudilder转toString;
        String s4=new String("abc");//构造方法4;StringBudilder转toString;
/*成员方法*/
        int a=s1.length();//返回字符串的长度,是一个方法,数组是属性
        /*System.out.println(s2==s4);//false
        System.out.println(s1==s4);//false
        System.out.println(s3==s1);//false
        System.out.println(s3==s4);//false*/
        boolean b=s1.equals(s3);//字符串内容比较区分大小写;
        boolean c=s3.equalsIgnoreCase(s4);//字符串内容比较不区分大小写;
        boolean d=s4.equalsIgnoreCase("abc");//字符串内容与指定字符串比较比较不区分大小写
        char e=s4.charAt(0);//返回指定字符串索引位置的字符;可用于字符串遍历;可直接用Arrays.toString()方法遍历;
       char[] f= s4.toCharArray();//返回字符串的指定成字符的数组;把字符串拆成字符数组;
        String g=s4.substring(1);//字符串从指定索引位置开始截取到末尾并返回;
        String h=s4.substring(1,2);//字符串从指定索引位置开始(包含)截取到指定位置结束(不包含)并返回;
        String i=s4.replace("a","c");//将字符串中的指定字符串替换成新的字符串并返回;
        String[] j=s4.split("b");//根据传入的字符串截取字符串并返回字符串数组;
        boolean k=s1.startsWith("a");//查询是不是以这个开头
        boolean l= s1.contains("a");//查询是不是包含指定字符

    }
}

=====================================

SystemStudy
public class SystemStudy {
    public static void main(String[] args) {
       /* exit(int status)//终止当前运行的   Java   虚拟机,非零表示异常终止
        public   static long currentTimeMillis()//返回当前时间(以毫秒为单位)
        arraycopy(数据源数组,起始索引,目的地数组,起始索引,复制个数)//数组复制*/
/*无构造方法,无法实例对象;类中的构造方法私有化,无法创建对象,成员方法全部静态,只需要用类名点方法名调用*/
/*成员方法*/
System.exit(0);//终止当前运行的   Java   虚拟机,非零表示异常终止
long s=System.currentTimeMillis();//返回当前时间(以毫秒为单位)
        int[]arr={1,2,3,4};
        int[]arr2=new int[10];
System.arraycopy(arr,0,arr2,0,arr.length);//数组复制,arraycopy(数据源数组,起始索引,目的地数组,起始索引,复制个数)
    }
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

20岁30年经验的码农

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值