• A quick reference quide to some useful methods.
  • Useful Methods Quick Reference

    String Methods Quick Reference

    Java String Page

  • char charAt(int index) - returns char at index
  • int compareTo(String anotherString)
  • boolean contains(String s) - returns true of string contains s
  • boolean equals(String s) - returns true if string equals s
  • int indexOf(String s [,fromIndex]) - returns index of s
  • boolean isEmpty() - returns true if string is “”
  • int length() - returns number of characters in string
  • String replace(String s, String t) - returns string where t replaces s
  • String substring(int begin) - returns substring from begin to length
  • String substring(int begin,int end) -returns substring from begin 2 end
  • char[] toCharArray() - returns char[] of string
  • String toLowerCase() - returns lowercase of string
  • String toUpperCase() - returns uppercase of string
  • Math Methods Quick Reference

    Java Math Page

  • double Math.random() - returns random double, 0 <= Math.random() < 1
  • double Math.pow(double a, double b) - returns ab
  • type Math.abs(type a) - returns absolute value, type can be double, int, float, long
  • long Math.round(double a) - returns rounded a
  • double Math.cos(double a) - returns cosine a
  • double Math.sin(double a) - returns sine a
  • static double Math.PI - pi
  • Scanner Methods Quick Reference

    Java Scanner Page

  • Scanner in = new Scanner(System.in);
  • int nextInt() - return next integer in input
  • double nextDouble() - return next double input
  • String nextLine() - return next line in input
  • String next() - return next word in input
  • boolean hasNextDouble() - return true if next token in input stream is a double
  • boolean hasNextInt() - return true if next token in input stream is an int
  • Random Methods Quick Reference

    Java Random Page

  • Random() - construct a Random object
  • Random(int seed) - construct a Random object with seed. Using the same seed will product the same sequence of random numbers.
  • int nextInt(int range) - returns random int from 0 to range-1
  • double nextDouble() - returns random double, 0 <= nextDouble() < 1
  • Arrays Methods Quick Reference

    Java Arrays Page

    The methods are shown for int[] arrays. Arrays has methods for arrays of all primitive types.

  • boolean equals(int[] a, int[] a2) - Returns true if the two specified arrays of ints are equal.
  • void fill(int[] a, int val) - Assigns the specified int val to each element of the specified array of ints.
  • String toString(int[] a) - Returns a string representation of the contents of the specified array.
  • static int[] copyOf(int[] original, int newLength) - Returns a new array that is a copy of original. The original array is truncated or padded with zeros (if necessary) so the copy has the specified length.