JAVA学习笔记- - - day 4

简介: # 字符串(重点)概述: 字符串不是基本数据类型,是类,是引用的数据类型。八种基本的数据类型: byte char short int long double float boolean## 字符串的常量String str = “hello”+new String("123"); 2到4可能在编译时,jvm对其优化,不会再运行是做加法运算处理## 字符串的构造器字符串的常量是一种定义的方式,还要其他形式的构造比如: 通过字符的数组,字节数组,## 空字符和null的区别空字符串是有效的引用,有地址的,只不过内容的长度为0null的引用是空的引

字符串(重点)

概述: 字符串不是基本数据类型,是类,是引用的数据类型。

八种基本的数据类型: byte char short int long double float boolean

字符串的常量

String str = “hello”+new String("123");    2到4

可能在编译时,jvm对其优化,不会再运行是做加法运算处理

字符串的构造器

字符串的常量是一种定义的方式,还要其他形式的构造

比如: 通过字符的数组,字节数组,

空字符和null的区别

空字符串是有效的引用,有地址的,只不过内容的长度为0

null的引用是空的引用,不能使用,使用会报空指针异常。

常用API方法

boolean contains(CharSequence s) Returns true if and only if this string contains the specified sequence of char values.
boolean endsWith(String suffix) Tests if this string ends with the specified suffix.
boolean equals(Object anObject) Compares this string to the specified object.
boolean equalsIgnoreCase(String anotherString) Compares this String to another String, ignoring case considerations.
String replace(CharSequence target, CharSequence replacement) Replaces each substring of this string that matches the literal target sequence with the specified literal replacement sequence.
String[] split(String regex) Splits this string around matches of the given regular expression.
boolean startsWith(String prefix) Tests if this string starts with the specified prefix.

StringBuffer

StringBuffer,是可以存储和操作字符串,即包含多个字符的字符串数据。String类是字符串常量,是不可更改的常量。而StringBuffer是字符串变量,它的对象是可以扩充和修改的

线程安全

StringBuilder

线程不安全

随机数

Random random = new Random();

常用方法:

Randomrandom=newRandom();

intrandomNum=random.nextInt(100) //随机获取[0,100)的随机数

可变参数方法

语法:

     权限修饰符 返回值  方法名称(类型... 变量名称){

    }

例如:

   //数据类型... 变量这是可变参数的定义方式

  //可以表示数组,也可以表示单个数据

// 如果调用的时候同时存在正好能匹配的方法,就不会调用这个可变参数的方法,否则是调用这个可变参数的方法

包装类(重点)

把基本数据类型转换成类,包装类提供了很多的方法给我们使用。

包装类 Byte Short Integer Long Float Character Boolean Double
基本数据类型 byte short int long float char boolean double

*自动拆箱**

拆箱就是自动将包装器类型转换为基本数据类型

       //这是一个Integer的对象

       Integeri1=newInteger(200);// 创建一个Integer的包装类型的对象

       inti3=i1;//自动拆箱

自动装箱

装箱就是自动将基本数据类型转换为包装器类型。

       inti4=200;

       Integeri5=i4;//自动装箱

比较的问题

Integer和int比较/运算时,Integer会自动拆箱成int

日期类Date(重点)

日期格式化

日期类:

Date

日期格式化:

SimpleDateFormat

获取日期的毫秒数:

System.currentTimeMillis();

作业:

Nature has given us that two ears, two eyes, and but one tongue, to the end that we should hear and see more than we speak

把最后一个two单词首字母大写


相关文章
|
1月前
|
Java 编译器 开发工具
Java基础学习笔记——idea篇
JDK由JRE(包含JVM和核心类库)和开发工具箱(如javac编译器和java运行工具)组成。Java项目结构包括Project、Module、Package和Class。IDEA快捷键包括:生成main方法(main psvm)、复制代码(Ctrl+D)、删除代码(Ctrl+Y/X)、格式化代码(Ctrl+Alt+L)、重命名(Shift+F6)等。
17 0
|
3月前
|
监控 负载均衡 Dubbo
|
4月前
|
前端开发 Java 数据安全/隐私保护
Java学习—GUI编程学习笔记
Java学习—GUI编程学习笔记
|
7月前
|
设计模式 存储 Java
【设计模式——学习笔记】23种设计模式——备忘录模式Memento(原理讲解+应用场景介绍+案例介绍+Java代码实现)
【设计模式——学习笔记】23种设计模式——备忘录模式Memento(原理讲解+应用场景介绍+案例介绍+Java代码实现)
57 0
|
7月前
|
Java 编译器
【Java学习笔记】 对象和类
【Java学习笔记】 对象和类
|
7月前
|
设计模式 存储 Java
【设计模式——学习笔记】23种设计模式——迭代器模式Iterator(原理讲解+应用场景介绍+案例介绍+Java代码实现)
【设计模式——学习笔记】23种设计模式——迭代器模式Iterator(原理讲解+应用场景介绍+案例介绍+Java代码实现)
29 0
|
5月前
|
存储 缓存 安全
《java核心技术36讲》学习笔记-------杨晓峰(极客时间)
《java核心技术36讲》学习笔记-------杨晓峰(极客时间)
62 0
|
2月前
|
存储 前端开发 Java
java学习笔记
java学习笔记
63 0
|
4月前
|
XML Java 数据格式
Spring5学习笔记——狂神说Java
Spring5学习笔记——狂神说Java
|
5月前
|
安全 Java
《深入理解java虚拟机》学习笔记-----郑雨迪
《深入理解java虚拟机》学习笔记-----郑雨迪
44 0