2019-03-31

接口

作用:结构设计工具,用来解耦合,隔离实现

接口是一个极端的抽象类

用interface代替class

用implements代替extends,把抽象接口实现

接口中只能定义:

公开的抽象方法

公开的常量

公开的内部类或者内部接口


内部类

非静态

非晶态内部类的对象,必须依赖于外部对象才能存在


class A{

         class Inner{

}

}


         A a1=new A()

A a2=new A()

Innner i= a1.new Inner()

静态内部类

一般用于关系紧密的两个类

class A{

         Static class Inner{

}

}

或者

class A{


}

Staticclass Inner{

}





[if !supportLists]  [endif]局部

方法中,局部代码块中定义

只能在方法内部使用



[if !supportLists]  [endif]匿名





基础API(APPLICATION PROGRAMMIMH INTERFACE)

应用编程接口


一切可以调用的东西


Object

[if !supportLists]n  [endif]java所有类的顶层父类

[if !supportLists]n  [endif]一个类如果不继承其他类,默认继承Object

[if !supportLists]n  [endif]方法

[if !supportLists]²  [endif]to String()

获得一个对像的字符串表示,

如果需要,可以在子类重写这个方法

[if !supportLists]²  [endif]equals(Object obj)

当前对象与参数对象obj比较是否相等

Object的默认实现是:

用双等号,比较内存地址this==obj

如果要比较对象的属性,可以在子类中重写这个方法。





String

[if !supportLists]n  [endif]创建String对象

[if !supportLists]²  [endif]char[] a={‘a’, ‘b’, ‘c’};

String s= new String(a);


[if !supportLists]²  [endif]第一种创建方式的简化语法

String s =”abcd”;

[if !supportLists]n  [endif]字符串的字面值

第一次使用字面值时,在“字符串的常量池”中新建对象

再次使用相同的字面值时,直接访问在“常量池”中存在的对象,而不新建

[if !supportLists]n  [endif]字符串不可变

每次加号连接运算都会新建字符串对象

字符串的加号连接效率低

       String s1=”aaa”

       String s2=”bbb”

       String s3=”ccc”

       String s4=s1+s2+s3



       String s4=”aaa”+”bbb”+”ccc”

       编译器在编译时,把代码优化成:

       String 4=”aaabbbccc”

       比变量连接要快

[if !supportLists]n  [endif]字符串的方法

[if !supportLists]²  [endif]charAt(i)

取i位置的字符

[if !supportLists]²  [endif]length()

字符串长度,字符的个数

[if !supportLists]²  [endif]indexOf(字串)

查找第一个子串的起始下标位置

String s=”abcdef”

int index=s.indexOf(“bc”)

如果字串不存在,返回特殊值-1

[if !supportLists]²  [endif]indexOf(子串,起始位置)

从指定位置向后查找

[if !supportLists]²  [endif]lastindexOf()

从后向前找

[if !supportLists]²  [endif]substring(from)

[if !supportLists]²  [endif]截取字串[ from,to




StringBuilder

StringBuffer

[if !supportLists]l  [endif]可变的字符序列

[if !supportLists]l  [endif]常用来代替字符串,做高效率字符串连接运算

append(数据)追加内容

[if !supportLists]ü  [endif]内部的数组默认初始容量是16

[if !supportLists]ü  [endif]存满,容量翻倍

[if !supportLists]ü  [endif]追加过程不会重复创建StringBuilder对象

[if !supportLists]ü  [endif]新建数组次数非常少,一次次翻倍,容量很容易很快变得很大


[if !supportLists]l  [endif]StringBuilder和StringBuffer的区别

[if !supportLists]²  [endif]StringBuilder线程不安全,效率高(多数情况下是单线程环境,不用考虑安全问题)

[if !supportLists]²  [endif]StringBuffer线程安全,效率低



正则表达式



基本类型的包装类

[if !supportLists]l  [endif]什么时候使用包装类

基本类型值,要当作引用类型(对象),可以把基本类型值包装成对象使用

void f(Object obj) {

}


f(new Interger(6))


[if !supportLists]l  [endif]Integer

[if !supportLists]²  [endif]创建对象

new Integer(6)

Integer.valueOf(6)

Integer类中,存在一个Integer对象的缓存数组,范围-128到127,

指定范围内的值,访问缓存对象

指定范围外的值,直接新建对象



ByteByte

ShortShort

 Integer

 Long

 Float

 Character





Date

[if !supportLists]l  [endif]日期

[if !supportLists]l  [endif]封装一个毫秒值,表示一个精确的时间点

[if !supportLists]l  [endif]创建Date对象

[if !supportLists]²  [endif]new Date()

封装系统当前时间的毫秒值

[if !supportLists]²  [endif]new Date(9000000)

封装指定的毫秒值

[if !supportLists]l  [endif]方法

[if !supportLists]²  [endif]getTime()

[if !supportLists]²  [endif]setTime(long t)

SimpleDateFormat

[if !supportLists]l  [endif]日期格式工具

[if !supportLists]l  [endif]Date对象----字符串

[if !supportLists]l  [endif]创建对象

new SimpleDateFormat(格式)

[if !supportLists]l  [endif]方法

[if !supportLists]l  [endif]format(对象)










BigDecimal, BigInterger

集合

[if !supportLists]l  [endif]用来存放一组数据的数据结构

[if !supportLists]l  [endif]数组的缺点:

[if !supportLists]1.        [endif]长度固定

[if !supportLists]2.        [endif]访问方式单一,只能用下标访问

[if !supportLists]3.        [endif]删除、插入数据时,操作繁琐,效率低

[if !supportLists]l  [endif]集合的继承结构

collection接口

  |-List接口

     |-ArrayList

     |-LinkedList

Map接口

Iterator接口



LinkedList


[if !supportLists]l  [endif]双向链表

[if !supportLists]l  [endif]两端效率高,越往中间效率越低

[if !supportLists]l  [endif]方法

[if !supportLists]²  [endif]add(数据)

在尾部添加数据

[if !supportLists]²  [endif]get(i)

访问指定下标位置的数据

[if !supportLists]²  [endif]remove(i)

移除指定位置的数据,返回被移除的数据

[if !supportLists]²  [endif]remove(数据)

找到相等数据并移除,返回true

没有找到相等的数据,返回false


[if !supportLists]²  [endif]size()

[if !supportLists]²  [endif]元素的数据,添加了多少个数据




[if !supportLists]²  [endif]iterator()

辅助新建迭代器对象的方法

it = list.iterator()

   ArrayList



[if !supportLists]l  [endif]内部是用数组存放数据

[if !supportLists]l  [endif]数组的初始容量是10

[if !supportLists]l  [endif]存满,容量1.5倍增长

[if !supportLists]l  [endif]访问任意位置,效率高

[if !supportLists]l  [endif]增删数据,效率可能降低

[if !supportLists]l  [endif]只在两端操作数据,用LinkedList

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 第一部分 HTML&CSS整理答案 1. 什么是HTML5? 答:HTML5是最新的HTML标准。 注意:讲述HT...
    kismetajun阅读 27,748评论 1 45
  • Lua 5.1 参考手册 by Roberto Ierusalimschy, Luiz Henrique de F...
    苏黎九歌阅读 13,907评论 0 38
  • 包(lib)、模块(module) 在Python中,存在包和模块两个常见概念。 模块:编写Python代码的py...
    清清子衿木子水心阅读 3,834评论 0 27
  • 对于java中的思考的方向,1必须要看前端的页面,对于前端的页面基本的逻辑,如果能理解最好,不理解也要知道几点。 ...
    神尤鲁道夫阅读 842评论 0 0
  • 一、笔记 一正则表达式 定义:记录文本规则的代码 近亲兄弟——通配符:在Windows系统中,通配符(wildca...
    安迪森阅读 279评论 0 0