Common Java Methods

Source: Internet
Author: User
Tags addall comparable stack pop



1.
byte[] b = {1,2,3,4,5,6,7};byte[] c = new Byte[5];void system.arraycopy (b,2,c,0,c.length);//after 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 Interruptede Xceptionpublic 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 start position 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 F Romindex) public int lastIndexOf (int. ch) public int indexOf (string str) public int indexOf (string str,int FromIndex) Public i NT LastIndexOf (String str) public string substring (int. Beginindex) public string substring (int beginindex,int EndIndex) public string Replace (char Oldchar,char Newchar)//replace All characters 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): add element boolean add (e e) void add (int index, e element) boolean addall (collectio n<? Extends E> C) boolean addall (int index, collection<? extends e> c) void AddFirst (e e) void AddLast (e E) boolean Offer (e-e)//element added to the end of Boolean Offerfirst (e) Boolean offerlast (e): gets the elements E element ()//gets the first elementE get (int Index)E getfirst () e getlast () e peek ()//get first element e Peekfirst () e peeklast (): Remove and get element e poll ()//first element e Pollfirst () e Pollla St () E remove ()//first element 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)//modify value boolean contains (object o) void clear () int size () Ob ject[] toArray () void push (e e)//stack push element e pop ()//stack pop-up element stack: public class stack<t> {private linkedlist<t> stor Age = 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 ();}
Queue: initqueue ()--initialize queue enqueue ()--into queue dequeue ()--out of queue Isqueueempty ()--determine if the queue is empty isqueuefull ()--determine if the queue is full pub Lic class Queue{private LinkedList storage = new LinkedList ();p ublic void clear ()//destroy Queue {Storage.clear ();} Public Boolean empty ()//determines whether the queue is empty {return Storage.isempty ();} public int length ()//get Queue Length {return storage.size ();} public void EnQueue (Object O)//enter Team {Storage.addfirst (o);} Public Object DeQueue ()//out of Team {If (!storage.isempty ()){return Storage.removelast ();}Return "queue is empty";} Public Object PEekQueue ()//view Team first element{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)//delete V put (K key, v value) void Putall (map<?) Extends K,? Extends v> m) v remove (object key)//query boolean containskey (object key) boolean containsvalue (object Value) v get (object Key) set<k> keySet () set<map.entry<k,v>> entryset ()//other 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 I sempty () 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)//two with the same element in the list returns 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)//copy A certain length static <T> t[] Co Pyofrange (t[] original, int from, Int. To)//copy a range of static Boolean equals (object[] a, object[] a2) public static Boolean deep Equals (object[] a1,object[] a2) static void sort (object[] a) static void sort (object[] a, int fromIndex, int Toindex) STA Tic <T> void sort (t[] a, comparator<? Super t> C)

Common Java Methods

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.