java常用方法

來源:互聯網
上載者:User

標籤:notify   sub   count   private   div   tin   ignore   hash   als   



1、
byte[] b = {1,2,3,4,5,6,7};byte[] c = new byte[5];void System.arraycopy(b,2,c,0,c.length);//後5個
2、new int[1].length;new String("1").length();3、Objectjava.lang.Object :11protected Object clone()throws CloneNotSupportedExceptionpublic boolean equals(Object obj)protected void finalize()throws Throwablepublic final Class<?> getClass()public int hashCode() public String toString()public final void notify()public final void notifyAll()public final void wait()throws InterruptedExceptionpublic final void wait(long timeout)throws InterruptedExceptionpublic final void wait(long timeout,int nanos)throws InterruptedException:public interface Cloneable--clone()
4、Stringpublic final class String extends Object implements Serializable, Comparable<String>, CharSequence
String(char[] value) String(char[] value, int offset, int count)//offset開始位置 String(StringBuffer buffer) 
public int length()public boolean isEmpty()public char charAt(int index)public void getChars(int srcBegin,int srcEnd,char[] dst,int dstBegin)
public char[] toCharArray()public static String copyValueOf(char[] data,int offset,int count)
public int compareTo(String anotherString) public boolean equals(Object anObject)public boolean equalsIgnoreCase(String anotherString)public boolean startsWith(String prefix)public boolean startsWith(String prefix,int toffset)public boolean endsWith(String suffix)public int indexOf(int ch)public int indexOf(int ch,int fromIndex)public int lastIndexOf(int ch)public int indexOf(String str)public int indexOf(String str,int fromIndex)public int lastIndexOf(String str)public String substring(int beginIndex)public String substring(int beginIndex,int endIndex)public String replace(char oldChar,char newChar)//替換所有字元public String replaceAll(String regex,String replacement)// replaceAll("\\\\","");
public String replaceFirst(String regex,String replacement)   public boolean matches(String regex)public String[] split(String regex)public String[] split(String regex,int limit)public String toLowerCase()public String toUpperCase()public String trim()public String toString():public interface Comparable<T>--int compareTo(T o)  
5、LinkedListpublic class LinkedList<E>extends AbstractSequentialList<E>implements List<E>, Deque<E>, Cloneable, Serializable
LinkedList(Collection<? extends E> c):添加元素boolean add(E e) void add(int index, E element)   boolean addAll(Collection<? extends E> c)  boolean addAll(int index, Collection<? extends E> c)  void addFirst(E e) void addLast(E e) boolean offer(E e) //元素添加到末尾boolean offerFirst(E e) boolean offerLast(E e) :擷取元素 E element()  //擷取第一個元素E get(int index)   E getFirst()  E getLast()  E peek()  //擷取第一個元素E peekFirst()  E peekLast() :移除並擷取元素 E poll() //第一個元素E pollFirst()  E pollLast() E remove()  //第一個元素E remove(int index) boolean remove(Object o) E removeFirst()  E removeLast()  int indexOf(Object o)    int lastIndexOf(Object o)  E set(int index, E element)  //修改值   boolean contains(Object o) void clear() int size() Object[] toArray() void push(E e) //堆棧壓入元素E pop() //堆棧彈出元素   棧:public class Stack<T> {private LinkedList<T> storage = new LinkedList<T>();
public void push(T v){storage.addLast(v);}public T peek(){return storage.getLast();}public T pop(){         if(!storage.isEmpty()){return storage.removeLast();}     }public boolean empty(){return storage.isEmpty();}
隊列:InitQueue()   ——初始化隊列EnQueue()        ——進隊列DeQueue()        ——出隊列IsQueueEmpty()——判斷隊列是否為空白IsQueueFull()    ——判斷隊列是否已滿public class Queue{private LinkedList storage = new LinkedList();public void clear()//銷毀隊列{storage.clear();}public boolean Empty()//判斷隊列是否為空白{return storage.isEmpty();}public int Length()//擷取隊列長度{return storage.size();}public void enQueue(Object o)//進隊{storage.addFirst(o);}public Object deQueue()//出隊{if(!storage.isEmpty()){return storage.removeLast();}return "隊列為空白";}public Object peekQueue()//查看隊首元素{return storage.getLast();}}
6、Mappublic class HashMap<K,V>extends AbstractMap<K,V>implements Map<K,V>, Cloneable, Serializable
HashMap(int initialCapacity) HashMap(Map<? extends K,? extends V> m) //增刪V put(K key, V value)  void putAll(Map<? extends K,? extends V> m) V remove(Object key) //查詢boolean containsKey(Object key)  boolean containsValue(Object value)V get(Object key) Set<K> keySet() Set<Map.Entry<K,V>> entrySet()  //其他void clear()  boolean isEmpty()    int size() Object clone() 
7、HashSetpublic class HashSet<E>extends AbstractSet<E>implements Set<E>, Cloneable, Serializable
HashSet(int initialCapacity) HashSet(Collection<? extends E> c) 
boolean add(E e)  boolean remove(Object o) boolean contains(Object o)  Iterator<E> iterator()  void clear()boolean isEmpty()int size()   Object clone() 
7、Collectionspublic class Collectionsextends Objectstatic <T> void copy(List<? super T> dest, List<? extends T> src) static boolean disjoint(Collection<?> c1, Collection<?> c2)  //兩列表中有相同元素則返回truestatic <T> boolean replaceAll(List<T> list, T oldVal, T newVal) static <T extends Comparable<? super T>> void sort(List<T> list)  static <T> void sort(List<T> list, Comparator<? super T> c)  public interface Comparator<T>{int compare(T o1, T o2);boolean equals(Object obj)  ;  }
8、Arrayspublic class Arraysextends Objectstatic <T> T[] copyOf(T[] original, int newLength)//複製一定長度  static <T> T[] copyOfRange(T[] original, int from, int to)//複製一定範圍static boolean equals(Object[] a, Object[] a2) public static boolean deepEquals(Object[] a1,Object[] a2)  static void sort(Object[] a) static void sort(Object[] a, int fromIndex, int toIndex) static <T> void sort(T[] a, Comparator<? super T> c) 

java常用方法

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.