Java Flashcards
How do you find a character at a certain index?
[String].charAt(int index)
How do you find the length of a string?
[String].length()
How do you obtain a sub string?
[String].substring(int beginIndex, int endIndex)
How do you test if the string contains a character?
[String].contains(CharSqequence s)
How do you replace all occurrences of a character?
[String].replace(char old, char new)
how do you convert a String to lowercase?
[String].toLowerCase()
How do you convert a String to uppercase?
[String].toUpperCase()
How do you remove spaces from the beginning and end of a String?
[String].trim()
How do you test if a String is empty>
[String].isEmpty()
How do you split a string?
[String].split(String regex, int limit)
How do you declare a new scanner for user input?
Scanner in = new Scanner(System.in)
How do you create a new scanner for a file?
Scanner in = new Scanner(File source)
How do you check if scanner can still read?
[Scanner].hasNext() or [Scanner].hasNextLine()
How do you grab next line from scanner?
[Scanner].nextLine()
How do you create a new File object?
File file = new File(“filename.txt”)
how do you declare array list?
ArrayList al = new ArrayList()
what are the three arraylist constructors?
ArrayList()
ArrayList(Collection extends E> c)
ArrayList(int initalCapacity)
How do you add an element to the arraylist?
[ArrayList].add(E e)
How do you insert an element at a specific index of an arraylist?
[ArrayList].add(int index, E e)
How do you add a collection to arraylist>
[ArrayList].addAll(Collection extends E> c)
How do you clear an arraylist?
[ArrayList].clear()
How do you create a shallow copy of the arraylist?
[ArrayList].clone()
How do you test if an arraylist contains an Object?
[ArrayList].contains(Object o)
How do you ensure a minimum capacity for an arrayList?
[ArrayList].ensureCapacity(int minCapacity)