码迷,mamicode.com
首页 > 编程语言 > 详细

Java经常使用类及其经常用法

时间:2017-07-10 20:08:31      阅读:165      评论:0      收藏:0      [点我收藏+]

标签:font   off   map接口   list   字符   clear   star   移除   用法   

1、ArrayList

java.util.ArrayList<E>

add(E e)              //插入尾部
add(int index, E element)
remove(int index)
remove(Object o)
get(int index)
indexOf()
lastIndexOf()
isEmpty()
size()
iterator()
listIterator()



java.util 接口 Iterator<E>

hasNext()
next()
remove()


2、Arrays 和Collections工具类

System.arraycopy(Object src, int srcPos, Object dest, int destPos, int length) 


java.util.Arrays

static int binarySearch()      //找不到则返回(-(插入点) - 1)。不一定是-1。
static boolean equals()       //推断数组相等
static void fill()      
static void sort()
static <T> void sort(T[] a, Comparator<?

super T> c) java.util.Collections static <T> int binarySearch(List<?

extends Comparable<?

super T>> list, T key) max(Collection<? extends T> coll) min(Collection<?

extends T> coll) static void reverse(List<?> list) sort(List<T> list) static <T> void sort(List<T> list, Comparator<? super T> c) static <T> Comparator<T> reverseOrder() //重要 java.util.接口Comparator<T> public interface Comparator<T> { int compare(T o1, T o2); boolean equals(Object obj); } java.lang.接口Comparable<T> public interface Comparable<T> { int compareTo(T o); } java.util.BitSet BitSet() BitSet(int nbits) //默认情况下,set中全部位的初始值都是false void clear(int bitIndex) //将索引指定处的位设置为 false。 void clear() //将此 BitSet 中的全部位设置为 false。 void flip(int index) //反转指定位 boolean get(int index) BitSet get(int from, int to) boolean isEmpty() //当没有不论什么true位时,返回true int length() //最高位索引+1(最高的1的索引。不是BitSet(10)中的9) void set(int bitIndex) //将指定索引处的位设置为 true。 void set(int fromIndex, int toIndex, boolean value) //将指定的 fromIndex(包含)到指定的 toIndex(不包含)范围内的位设置为指定的值。

String toString() //返回字符串表示,bs.set(4);bs.set(6);之后为"{4,6}"



3、HashMap

java.util.HashMap<K, V>

boolean containsKey(Object key) 
boolean containsValue(Object value) 
Set<Map.Entry<K,V>> entrySet() 
V get(Object key)
boolean isEmpty()
Set<K> keySet()
V put(K key, V value)       //加入键值对,假设存在key。则替换value
V remove(Object key)
int size()




java.util.接口 Map.Entry<K,V>         //是Map接口的静态内部接口

public static interface Map.Entry<K,V>

K getKey()
V getValue()
V setValue(V value)


4、HashSet

java.util.HashSet<E>


boolean add(E e)
boolean remove(Object o)
boolean contains(Object o)
boolean isEmpty()
int size()
Iterator<E> iterator()


5、LinkedList

java.util.LinkedList<E>


public class LinkedList<E> extends AbstractSequentialList<E>
implements List<E>, Deque<E>, Cloneable, Serializable



boolean add(E e)                    //加到末尾
void addFirst(E e)
void addLast(E e)
E removeFirst()
E removeLast()

E element()                   //获取但不移除头
E get(int index)
E getFirst()
E getLast()

int indexOf(Object o)                 //不包括则返回-1
int lastIndexOf(Object o)             //不包括则返回-1
boolean contains(Object o)

int size()
Iterator<E> iterator()

E set(int index, E element)



6、Object

finalize()
clone()

3个wait()
notify()
notifyAll()

getClass()
equals()
hashCode()
toString()


一共11个方法!!


7、Pattern 和 Matcher

java.util.regex.Pattern


static Pattern compile(String regex)
static boolean matches(String regex, CharSequence input)

Matcher matcher(CharSequence input)




java.util.regex.Matcher


while(m.find()) {
	String str1 = m.group();
	String str2 = m.group(2);
	boolean b1 = m.lookingAt();        //头部匹配
	boolean b2 = m.matches();
}

int start()    //曾经匹配的初始索引
int end()	//曾经最后匹配字符之后一个字符的偏移量
Matcher reset()  //重置匹配器
String replaceAll(String replacement)     //替换模式与给定替换字符串相匹配的输入序列的每一个子序列。
String replaceFirst(String replacement)

8、String

static Comparator<String> CASE_INSENSITIVE_ORDER;

charAt()
compareTo()
compareToIgnoreCase()
contains()
startsWith()
endsWith()
equals()             //推断字符串相等不能用==
indexOf()
lastIndexOf()
isEmpty()
length()
matches(String regex)
replace()
replaceAll(String regex, String replacement)
replaceFirst(String regex, String replacement)
String[] split(String regex)
substring(int begin)                  //注意方法写法
substring(int begin, int end)          //注意方法写法, end不包含
toLowerCase()
toUpperCase()
trim()                      //忽略前后的空白


9、StringBuilder

StringBuilder()
StringBuilder(String str)


append()
capacity()   与length()的差别!

!建议忘了它吧!!

charAt() delete(int start, int end) //不包括end indexOf() lastIndexOf() insert(int offset, CharSequence s) length() reverse() substring(int begin) //注意方法写法 substring(int begin, int end) //注意方法写法, end不包括 String toString() 没有没有equals()方法!!!

!!!

!!

没有没有equals()方法!

。!!!。!

没有没有equals()方法。。!!!

。!!



Java经常使用类及其经常用法

标签:font   off   map接口   list   字符   clear   star   移除   用法   

原文地址:http://www.cnblogs.com/claireyuancy/p/7147342.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!