Java Arrays and String Methods - Cheat Sheet
Arrays Methods
1. sort(arr): Sorts the array in ascending order.
Example: [Link](arr);
2. binarySearch(arr, key): Returns index of key, or negative insertion point.
Example: [Link](arr, 5);
3. fill(arr, val): Fills all elements with val.
Example: [Link](arr, 7);
4. equals(arr1, arr2): Returns true if arrays are equal.
Example: [Link](a, b);
5. copyOf(arr, newLength): Copies array to new length.
Example: [Link](arr, 3);
6. copyOfRange(arr, from, to): Copies a range.
Example: [Link](arr, 1, 3);
7. toString(arr): Returns string representation.
Example: [Link](arr);
8. deepToString(nested): For nested arrays.
Example: [Link](nested);
9. hashCode(arr): Returns hash of array.
Example: [Link](arr);
10. parallelSort(arr): Faster parallel sort.
Example: [Link](arr);
11. setAll(arr, lambda): Fills with lambda result.
Example: [Link](arr, i -> i*i);
String Methods
1. length(): Returns string length.
Example: [Link]();
2. charAt(i): Returns char at index i.
Example: [Link](1);
3. substring(start, end): Substring of string.
Example: [Link](1, 3);
4. equals(str): Compares strings.
Java Arrays and String Methods - Cheat Sheet
Example: [Link]("hello");
5. equalsIgnoreCase(str): Case-insensitive comparison.
Example: [Link]("HELLO");
6. compareTo(str): Lexicographical compare.
Example: "a".compareTo("b");
7. contains(seq): Checks for sequence.
Example: [Link]("ell");
8. indexOf(ch): Index of first occurrence.
Example: [Link]('l');
9. startsWith(prefix): Checks prefix.
Example: [Link]("he");
10. endsWith(suffix): Checks suffix.
Example: [Link]("lo");
11. toUpperCase()/toLowerCase(): Case conversion.
Example: [Link]();
12. trim(): Removes leading/trailing spaces.
Example: " hi ".trim();
13. replace(old, new): Replaces characters.
Example: [Link]('l', 'x');
14. split(regex): Splits into array.
Example: "a,b".split(",");
15. valueOf(val): Converts to string.
Example: [Link](123);
16. isEmpty()/isBlank(): Checks emptiness (Java 11+ for isBlank).
Example: "".isEmpty(); " ".isBlank();