Skip to content

Instantly share code, notes, and snippets.

@srsandy
Last active March 13, 2021 07:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save srsandy/25de9c33ff20c0b1d0d29ee72aba9b37 to your computer and use it in GitHub Desktop.
Save srsandy/25de9c33ff20c0b1d0d29ee72aba9b37 to your computer and use it in GitHub Desktop.
Java Methods for Interviews

Methods that can help you code quicker and better.

String/Array

toCharArray() //get char array of a String

charAt(int x) //get a char at the specific index

length() //string length

length //array size 

substring(int beginIndex) 

substring(int beginIndex, int endIndex)

Integer.valueOf() //string to integer

String.valueOf() //integer to string

Arrays.sort()  //sort an array

Arrays.toString(char[] a) //convert to string

Arrays.copyOf(T[] original, int newLength)

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

isEmpty() //checks whether a string is empty or not.

compareTo(String s) //compares two strings lexicographically
//The method returns 0 if the string is equal to the other string. A value less than 0 is returned if the string is less than the other //string (less characters) and a value greater than 0 if the string is greater than the other string (more characters).

compareToIgnoreCase(String s) //compares two strings lexicographically, ignoring lower case and upper case differences.

ArrayList

 Collections.min(List<T> list)
  
 Collections.max(List<T> list)
  
 indexOf(Object value)
  
 b.set(int index, Object newValue);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment