Analysis of common methods in Java class and data structure _java

Source: Internet
Author: User
Tags int size

The methods used in the 1.Object class are:

Protected Object Clone () creates and returns a copy of this object.

Boolean equals (Object obj) indicates whether another object is "equal" to this object.

protected void Finalize () This method is called by the object's garbage collector when the garbage collector determines that there are no more references to the object.

Class<?> GetClass () returns the Run-time class for this Object.

int Hashcode () returns the hash code value for this object.

void Notify () wakes a single thread waiting on this object monitor.

void Notifyall () wakes all threads waiting on this object monitor.

String toString () returns a string representation of the object.

void Wait () results in the current thread waiting before other threads call the Notify () method or Notifyall () method of this object.

void wait (long timeout) causes the current thread to await when other threads call the object's notify () method or Notifyall () method, or before the specified amount of time.

void Wait (long timeout, int Nanos) calls this object's notify () method or Notifyall () method on another thread, or if another thread interrupts the current thread, or before a certain amount of actual time has passed, causing the current thread to await.

The methods commonly used in 2.Iterator interfaces are:

A.boolean Hasnext () to determine if there is a next element

B.E Next () returns the next element

c.void Remove () deletes the last element

The methods commonly used in 3.ListIterator interfaces are:

A.boolean Hasnext () to determine if there is a next element

B.E Next () returns the next element

c.int Nextindex () returns the subscript for the next element

D.boolean hasprevious (); whether there is a previous element;

e.e Previous (); returns the previous element;

f.int previousindex (); Returns the subscript of the previous element;

g.void Set (e e); Set element.

h.void Add (e e);

The method inside the 4.Collection class:

A.boolean Add (e E) ensures that this collection contains the specified element.

B.boolean AddAll (collection<? extends e> c) adds all the elements in the specified Collection to this Collection (optional operation).

c.void Clear () Removes all elements in this collection (optional operation).

D.boolean equals (object o) compares whether this collection is equal to the specified object.

E.boolean IsEmpty () This returns True if the collection contains no elements.

F. Iterator<e> iterator () returns an iterator that iterates over the elements on this collection.

g.boolean Remove (Object o) removes a single instance of the specified element from this collection, if present.

H.boolean RemoveAll (collection<?> c) Removes all elements in this Collection that are also included in the specified Collection.

i.int Size () returns the number of elements in this collection.

j.object[] ToArray () returns an array that contains all the elements in this collection.

k.<t> t[] ToArray (t[] a) returns an array containing all the elements in this collection, and the Run-time type of the array returned is the same as the run-time type of the specified array.

5.Map interface

The number of key-value pairs contained in the a.int size () map;

Whether there are elements in the B.boolean IsEmpty () map;

C.boolean ContainsKey (Object key) to determine whether key value pairs are included;

D.boolean containsvalue (Object value) determines whether a key value pair is included for value.

e.v get (Object key) Gets the value of the key; V is the type of value

F.V put (K key,v value) places the key value pair in the map.

g.v Remove (Object key) deletes the key value.

h.void putall (map<? K>,< extends M) put the key-value pairs in another Map.

i.void Clear (); empty all key-value pairs in the map.

j.set<k> Setkey (); Returns a collection of key keys.

k.collection<v> values (); Returns a list of value.

l.set<map.entry<k,v>> entryset (); Returns all key value pairs in this Map in the form of Entry entities.

M.boolean equals (object o), which indicates whether an object is equal to this object;

n.int hashcode (); Returns the hash value of the object.

The 6.String class is a final class that cannot be inherited.

char charAt (int index) returns the index character in the string;

int length () returns the length of the string;

int indexOf (String str) returns the position of the first occurrence of STR in the string;

int indexOf (string str,int fromindex) returns the position of the first occurrence of STR at the beginning of the Fromindex;

Boolean equalsignorecase (String another) compares the string to another (ignoring case);

String replace (char Oldchar,char Newchar) replaces Oldchar characters with Newchar characters in strings

Boolean startswith (string prefix) to determine whether a string starts with a prefix string

Boolean endsWith (string suffix) determines whether a string ends with a suffix string;

String toUpperCase () returns a string that is an uppercase form of the string;

String toLowerCase () returns a string that is a lowercase form of the string

string substring (int beginindex) returns a substring of the string starting from Beginindex to the end; string substring (int beginindex,int endindex) Returns the substring of the string starting from Beginindex to the end of Endsindex

String Trim () returns the string after the string is removed from the start and end spaces

String[] Split (string regex) separates a string by the specified delimiter, returning a delimited array of strings

int lastindexof (int ch) only find the position of the last matching string.

int lastindexof (int ch, int fromindex) only find the position of the last matching string starting from Fromindex.

int LastIndexOf (string str) only places the last matching string.

The int lastindexof (string str, int fromindex) only find the position of the last matching string starting from Fromindex.

int hashcode (): Returns the hash table code for the current character.

int indexOf (int ch): Find only the first matching character position.

int indexOf (int ch, int fromindex): Start with Fromindex to find the first matching character position.

int indexOf (String str): Only the first matching string position is found.

int indexOf (String str, int fromindex): Starts from Fromindex to find the first matching string position.

Byte[] GetBytes (): Converts the string object to a byte array.

void GetChars (int srcbegin, int srcend, char[] DST, int dstbegin): This method copies a string into a character array. Where the srcbegin is the starting position of the copy, the srcend is the ending position of the copy, the string value DST is the target character array, and the Dstbegin is the copy starting position of the target character array.

The above analysis of Java classes and data structure commonly used methods are small to share all the content of everyone, hope to give you a reference, but also hope that we support the cloud habitat community.

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.