Java笔记新编基础篇.docx

上传人:b****8 文档编号:23733091 上传时间:2023-05-20 格式:DOCX 页数:36 大小:27.45KB
下载 相关 举报
Java笔记新编基础篇.docx_第1页
第1页 / 共36页
Java笔记新编基础篇.docx_第2页
第2页 / 共36页
Java笔记新编基础篇.docx_第3页
第3页 / 共36页
Java笔记新编基础篇.docx_第4页
第4页 / 共36页
Java笔记新编基础篇.docx_第5页
第5页 / 共36页
点击查看更多>>
下载资源
资源描述

Java笔记新编基础篇.docx

《Java笔记新编基础篇.docx》由会员分享,可在线阅读,更多相关《Java笔记新编基础篇.docx(36页珍藏版)》请在冰豆网上搜索。

Java笔记新编基础篇.docx

Java笔记新编基础篇

目录

第一章常用类4

一、String4

1.String类的判断功能4

2.String类的获取功能4

3.String类的转换功能4

4.替换功能4

5.去除字符串两端空格5

6.按字典顺序比较两个字符串5

二、StringBuffer5

1.构造方法5

2.添加功能5

3.删除功能5

4.替换功能5

5.反转功能5

6.截取功能5

三、正则表达式的应用5

1.判断功能5

2.分割功能6

3.替换功能6

4.获取功能6

5.正则表达式规则6

四、Math7

五、Random8

六、System8

七、BigInteger8

八、BigDecimal9

九、Date和DateFormat9

1.Date构造方法9

2.Date成员方法9

3.SimpleDateFormat构造方法9

4.SimpleDateFormat成员方法9

5.日期和时间模式9

第二章集合10

十、Collection接口10

1:

添加功能10

2:

删除功能10

3:

判断功能10

4:

获取功能(迭代器)10

5:

长度功能11

6:

把集合转换为数组11

7:

泛型通配符

>11

十一、List接口11

A:

添加功能11

B:

获取功能11

C:

列表迭代器11

D:

删除功能11

E:

修改功能11

F:

List的子类特点11

G:

ArrayList12

H:

Vector12

I:

LinkedList12

十二、Set接口13

1.HashSet13

1.1、hashCode13

1.2、equals13

2.TreeSet14

2.1实现Comparable接口14

2.2接收Comparator的实现类对象14

3.LinkedHashSet14

十三、Collection集合总结14

十四、Map15

1:

添加功能15

2:

删除功能15

3:

判断功能15

4:

获取功能16

5:

长度功能16

6:

子类16

6.1HashMap:

16

6.2LinkedHashMap:

16

6.3TreeMap:

16

十五、Collections16

1.Collection和Collections的区别17

2.成员方法17

第三章文件与IO流17

十六、File17

1.创建功能17

2.删除功能:

17

3.重命名功能:

17

4.判断功能:

17

5.获取功能17

十七、IO流18

1.FileOutputStream、OutputStream、BufferedOutputStream;18

2.FileInputStream、InputStream、BufferedInputStream;18

3.转换流18

4.转换流的简化写法19

5.字符缓冲流19

6.IO流小结IO流20

第四章线程21

十八、继承Thread21

1.成员方法21

十九、实现Runnable接口24

1.实现Runnable接口24

2.线程同步25

3.Lock25

第一章常用类

一、String

1.String类的判断功能

booleanequals(Objectobj)

/*将此String与另一个String比较,不考虑大小写*/

booleanequalsIgnoreCase(Stringstr)

booleancontains(Stringstr)

booleanstartsWith(Stringstr)

booleanendsWith(Stringstr)

booleanisEmpty()

2.String类的获取功能

intlength()

charcharAt(intindex)

/*返回指定字符在此字符串中第一次出现处的索引*/

intindexOf(intch)

intindexOf(Stringstr)

/*返回在此字符串中第一次出现指定字符处的索引,从指定的索引开始搜索。

*/

intindexOf(intch,intfromIndex)

intindexOf(Stringstr,intfromIndex)

Stringsubstring(intstart)

Stringsubstring(intstart,intend)

3.String类的转换功能

byte[]getBytes()//字节码

char[]toCharArray()//字符数组

staticStringvalueOf(char[]chs)

staticStringvalueOf(inti)

StringtoLowerCase()//转成小写

StringtoUpperCase()大写

Stringconcat(Stringstr)//将指定字符串连接到此字符串的结尾

4.替换功能

Stringreplace(charold,charnew)

Stringreplace(Stringold,Stringnew)

5.去除字符串两端空格

Stringtrim()

6.按字典顺序比较两个字符串

intcompareTo(Stringstr)

intcompareToIgnoreCase(Stringstr)

二、StringBuffer

1.构造方法

publicStringBuffer()

publicStringBuffer(intcapacity)

publicStringBuffer(Stringstr)

2.添加功能

publicStringBufferappend(Stringstr)//拼接

publicStringBufferinsert(intoffset,Stringstr)//插入

3.删除功能

publicStringBufferdeleteCharAt(intindex)

publicStringBufferdelete(intstart,intend)

4.替换功能

publicStringBufferreplace(intstart,intend,Stringstr)

5.反转功能

publicStringBufferreverse()

6.截取功能

publicStringsubstring(intstart)

publicStringsubstring(intstart,intend)

三、正则表达式的应用

1.判断功能

publicbooleanmatches(Stringregex)

2.分割功能

publicString[]split(Stringregex)

3.替换功能

publicStringreplaceAll(Stringregex,Stringreplacement)

4.获取功能

Pattern和Matcher类的使用

5.正则表达式规则

A:

字符

x字符x。

举例:

'a'表示字符a

\\反斜线字符。

\n新行(换行)符('\u000A')

\r回车符('\u000D')

B:

字符类

[abc]a、b或c(简单类)

[^abc]任何字符,除了a、b或c(否定)

[a-zA-Z]a到z或A到Z,两头的字母包括在内(范围)

[0-9]0到9的字符都包括

C:

预定义字符类

.任何字符。

我的就是.字符本身,怎么表示呢?

\.

\d数字:

[0-9]

\w单词字符:

[a-zA-Z_0-9]

在正则表达式里面组成单词的东西必须有这些东西组成

D:

边界匹配器

^行的开头

$行的结尾

\b单词边界

就是不是单词字符的地方。

举例:

helloworld?

haha;xixi

E:

Greedy数量词

X?

X,一次或一次也没有

X*X,零次或多次

X+X,一次或多次

X{n}X,恰好n次

X{n,}X,至少n次

X{n,m}X,至少n次,但是不超过m次

例:

importjava.util.Scanner;

/*

*校验邮箱

*

*分析:

*A:

键盘录入邮箱

*B:

定义邮箱的规则

*1517806580@

*liuyi@

*linqingxia@

*fengqingyang@

*fqy@

*C:

调用功能,判断即可

*D:

输出结果

*/

publicclassRegexTest{

publicstaticvoidmain(String[]args){

//键盘录入邮箱

Scannersc=newScanner(System.in);

System.out.println("请输入邮箱:

");

Stringemail=sc.nextLine();

//定义邮箱的规则

//Stringregex="[a-zA-Z_0-9]+@[a-zA-Z_0-9]{2,6}(\\.[a-zA-Z_0-9]{2,3})+";

Stringregex="\\w+@\\w{2,6}(\\.\\w{2,3})+";

//调用功能,判断即可

booleanflag=email.matches(regex);

//输出结果

System.out.println("flag:

"+flag);

}

}

四、Math

publicstaticintabs(inta)//

/*返回最小的(最接近负无穷大)double值,该值大于等于参数,并等于某个整数。

*/

publicstaticdoubleceil(doublea)

 

/*返回最大的(最接近正无穷大)double值,该值小于等于参数,并等于某个整数*/

publicstaticdoublefloor(doublea)

publicstaticintmax(inta,intb)min自学

publicstaticdoublepow(doublea,doubleb)

publicstaticdoublerandom()

/*返回最接近参数的int。

参数为double时,返回值为long*/

publicstaticintround(floata)参数为double的自学

publicstaticdoublesqrt(doublea)

五、Random

构造方法:

publicRandom()

publicRandom(longseed)

成员方法:

publicintnextInt()

publicintnextInt(intn)

六、System

publicstaticvoidgc()//    运行垃圾回收器。

publicstaticvoidexit(intstatus)

/*返回以毫秒为单位的当前时间*/

publicstaticlongcurrentTimeMillis()

publicstaticvoidarraycopy(Objectsrc,intsrcPos,Objectdest,intdestPos,intlength)

七、BigInteger

构造方法

publicBigInteger(Stringval)

成员方法

publicBigIntegeradd(BigIntegerval)//加

publicBigIntegersubtract(BigIntegerval)//减

publicBigIntegermultiply(BigIntegerval)//乘

publicBigIntegerdivide(BigIntegerval)//除

/*返回包含(this/val)后跟(this%val)的两个BigInteger的数组。

*/

publicBigInteger[]divideAndRemainder(BigIntegerval)

八、BigDecimal

publicBigDecimaladd(BigDecimalaugend)

publicBigDecimalsubtract(BigDecimalsubtrahend)

publicBigDecimalmultiply(BigDecimalmultiplicand)

publicBigDecimaldivide(BigDecimaldivisor)

九、Date和DateFormat

1.Date构造方法

publicDate()

publicDate(longdate)

2.Date成员方法

publiclonggetTime()

publicvoidsetTime(longtime)

3.SimpleDateFormat构造方法

publicSimpleDateFormat()

publicSimpleDateFormat(Stringpattern)

4.SimpleDateFormat成员方法

/*将一个Date格式化为日期/时间字符串*/

publicfinalStringformat(Datedate)

/8 从给定字符串的开始解析文本,以生成一个日期。

*/

publicDateparse(Stringsource)

5.日期和时间模式

字母

日期或时间元素

表示

示例

G

Era标志符

Text

AD

y

Year

1996;96

M

年中的月份

Month

July;Jul;07

w

年中的周数

Number

27

W

月份中的周数

Number

2

D

年中的天数

Number

189

d

月份中的天数

Number

10

F

月份中的星期

Number

2

E

星期中的天数

Text

Tuesday;Tue

a

Am/pm标记

Text

PM

H

一天中的小时数(0-23)

Number

0

k

一天中的小时数(1-24)

Number

24

K

am/pm中的小时数(0-11)

Number

0

h

am/pm中的小时数(1-12)

Number

12

m

小时中的分钟数

Number

30

s

分钟中的秒数

Number

55

S

毫秒数

Number

978

z

时区

Generaltimezone

PacificStandardTime;PST;GMT-08:

00

Z

时区

RFC822timezone

-0800

第二章集合

一十、Collection接口

1:

添加功能

booleanadd(Objectobj):

添加一个元素

booleanaddAll(Collectionc):

添加一个集合的元素

2:

删除功能

voidclear():

移除所有元素

booleanremove(Objecto):

移除一个元素

booleanremoveAll(Collectionc)

移除此collection中那些也包含在指定collection中的所有元素(可选操作)。

此调用返回后,collection中将不包含任何与指定collection相同的元素。

3:

判断功能

booleancontains(Objecto):

判断集合中是否包含指定的元素

booleancontainsAll(Collectionc):

判断集合中是否包含指定的集合元素(是一个还是所有)

booleanisEmpty():

判断集合是否为空

4:

获取功能(迭代器)

Iteratoriterator()(重点)

Collectionc=newArrayList();

c.add("hello");

c.add("world");

c.add("java");

Iteratorit=c.iterator();

while(it.hasNext()){

Strings=(String)it.next();

System.out.println(s);

}

5:

长度功能

intsize():

元素的个数

6:

把集合转换为数组

Object[]toArray()

7:

泛型通配符

>

?

extendsE向下限定,E及其子类

?

superE向上限定,E及其父类

一十一、List接口

A:

添加功能

voidadd(intindex,Objectelement):

在指定位置添加元素

B:

获取功能

Objectget(intindex):

获取指定位置的元素

C:

列表迭代器

ListIteratorlistIterator():

List集合特有的迭代器

例:

ListIteratorlit=list.listIterator();//子类对象

while(lit.hasNext()){

Strings=(String)lit.next();

System.out.println(s);

}

D:

删除功能

Objectremove(intindex):

根据索引删除元素,返回被删除的元素

E:

修改功能

Objectset(intindex,Objectelement):

根据索引修改元素,返回被修饰的元素

F:

List的子类特点

ArrayList

底层数据结构是数组,查询快,增删慢。

线程不安全,效率高。

Vector

底层数据结构是数组,查询快,增删慢。

线程安全,效率低。

LinkedList

底层数据结构是链表,查询慢,增删快。

G:

ArrayList

ArrayListarray=newArrayList();

//创建并添加元素

array.add("hello");

array.add("world");

array.add("java");

//增强for

for(Strings:

array){

System.out.println(s);

}

H:

Vector

A:

有特有功能

a:

添加

publicvoidaddElement(Eobj)--add()

b:

获取

publicEelementAt(intindex)--get()

publicEnumerationelements()--

I:

LinkedList

a:

添加

addFirst()

addLast()

b:

删除

removeFirst()

removeLast()

c:

获取

getFirst()

getLast()

一十二、Set接口

1.HashSet

A:

底层数据结构是哈希表(是一个元素为链表的数组)

B:

哈希表底层依赖两个方法:

hashCode()和equals()

执行顺序:

首先比较哈希值是否相同

相同:

继续执行equals()方法

返回true:

元素重复了,不添加

返回false:

直接把元素添加到集合

不同:

就直接把元素添加到集合

C:

如何保证元素唯一性的呢?

由hashCode()和equals()保证的

1.1、hashCode

publicinthashCode(){

finalintprime=31;

intresult=1;

result=prime*result+age;

result=prime*result+((name==null)?

0:

name.hashCode());

returnresult;

}

1.2、equals

publicbooleanequals(Objectobj){

if(this==obj)

returntrue;

if(obj==null)

returnfalse;

if(getClass()!

=obj.getClass())

returnfalse;

Studentother=(Student)obj;

if(age!

=other.age)

returnfalse;

if(name==null){

if(other.name!

=null)

returnfalse;

}elseif(!

name.equals(other.name))

returnfalse;

returntrue;

}

2.TreeSet

A:

底层数据结构是红黑树(是一个自平衡的二叉树)

B:

保证元素的排序方式

a:

自然排序(元素具备比较性)

让元素所属的类实现Comparable接口

b:

比较器排序(集合具备比较性)

让集合构造方法接收Comparator的实现类对象

2.1实现Comparable接口

publicclassStudentimplementsComparable{

privateintage;

privateStringname;

//重写

publicintcompareTo(Students){

intnum1=this.name.length()-s.getName().length();

intnum2=num1==0?

p

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 法律文书 > 起诉状

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1