java brush question reference function

In my way of brushing questions, python first quickly grasps the algorithm ideas, and on this basis, tries multilingual solutions according to needs.

table of Contents:

  1. Arrays
  2. Map
  3. Math
  4. String
  5. List
  6. Vector
  7. Queue
  8. Set
  9. Stack

Arrays usage:

  1. Arrays.copyOf (array, length) copy algorithm
  2. Arrays.sort (double []) sort in ascending order
  3. Arrays.asList (arr) .contains () Determine whether the array contains an element

Map usage:
5. Map <T, T> map = new HashMap <
6. Map.get (key): get value
7. Map.getOrDefault (Object key, V defaultValue): equivalent to setdefault
8. Map in python . put (key, value): add key-value pairs
9. Map.keySet (): all key value sets in the map

Math usage:
10. Math.max (Array) gets the maximum value
11. Math.abs () gets the absolute value
10. Math.pow () gets the exponent

String:

  1. Integer.parseInt (str): string to number
  2. str.length (): string length
  3. str.charAt (i): Get the ith character of a string
  4. str1.compareToIgnoreCase (str2): String comparison ignoring size
  5. str1.compareTo (str2): String comparison ignoring size
  6. str.equals (String ostr): Determine whether two strings are equal
  7. str.indexOf (ch): Find where the character / string appears
  8. str.substring(beginIndex, endIndex)
  9. str.split (regular expression): save the split result in a string array
  10. str1.concat (str2): merge str1 and str2
  11. str.toLowerCase (): Convert all strings to lowercase
  12. str.toUpperCase (): Convert all characters to uppercase
  13. str.trim (): Ignore leading and trailing spaces
  14. str.replace(lodeChar, newChar)
  15. str.split (): The return value is a string array
  16. str.toCharArray()

StringBuilder:
append (parameter): append content to the end of StringBuilder
insert (position, parameter): insert content into the specified position
toString: StringBuilder into String
int length: length

List:

  1. List person = new ArrayList <> (): mostly used for searching through traversal
  2. LinkedList person = new LinkedList (); mostly used to insert and delete
  3. add (obj): add an element
  4. remove (index / obj): remove the element
  5. get (index): get the element
  6. size: Get length
  7. set (index, target): modify the element value at the index
  8. Collections.sort(List<> l)

Vector

  1. Vector add (int index, Object element): add at the specified position
  2. add (Object o): add to the end
  3. addAll (Collection c): Join in the order of collection iteration
  4. int capacity (): returns the current capacity
  5. void clear (): clear all elements
  6. clone (): clone a copy
  7. elementAt (int index): Returns the component at the specified index.
  8. Object get (int index): Returns the element at the specified position in the vector.
  9. boolean isEmpty()

Queue

  1. add add a meta cable if the queue is full, throw a IIIegaISlabEepeplian exception
  2. remove removes and returns the element at the head of the queue. If the queue is empty, a NoSuchElementException is thrown
  3. element returns the element at the head of the queue. If the queue is empty, a NoSuchElementException is thrown.
  4. offer add an element and return true if the queue is full, return false
  5. poll removes and returns the element at the head of the queue. If the queue is empty, returns null
  6. peek returns the element at the head of the queue or null if the queue is empty
  7. put adds an element and blocks if the queue is full
  8. take removes and returns the element at the head of the queue. If the queue is empty, block

Set

  1. Set seen = new HashSet();
  2. Set.add (): add elements
  3. Set.contains (value): determine whether the set contains value

Stack

  1. boolean empty()
  2. Object peek( )
  3. Object pop( )
  4. Object push(Object element)
  5. int search(Object element)

other:

  1. String.valueOf (n) .toCharArray (): Number to character array
  2. PriorityQueue pq = new PriorityQueue((k1, k2) -> grid[k1 / N][k1 % N] - grid[k2/N][k2%N]);
Published 16 original articles · Like1 · Visits 371

Guess you like

Origin blog.csdn.net/qq_41174940/article/details/104689887