Interview Java Q's Flashcards
How do you create a Scanner object to read input from console?
Scanner scanner = new Scanner(System.in);
What Scanner method reads an entire line as a String?
scanner.nextLine()
What Scanner method reads the next integer value?
scanner.nextInt()
How do you print output without a new line in Java?
System.out.print()
How do you print output with a new line in Java?
System.out.println()
How do you get the length of a String?
string.length()
How do you get a character at a specific index in a String?
string.charAt(index)
How do you extract a portion of a String from start index (inclusive) to end index (exclusive)?
string.substring(startIndex, endIndex)
How do you convert a String to uppercase?
string.toUpperCase()
How do you convert a String to lowercase?
string.toLowerCase()
How do you remove whitespace from beginning and end of a String?
string.trim()
How do you split a String into an array using a delimiter?
string.split(delimiter)
How do you convert a String to an integer?
Integer.parseInt(string)
How do you convert a String to a double?
Double.parseDouble(string)
How do you convert a number to a String?
String.valueOf(number)
How do you create an empty ArrayList?
ArrayList<Type> list = new ArrayList<>();
ArrayList<String> cars = new ArrayList<String>();
How do you add an element to a List?
list.add(element)
How do you remove an element at a specific index from a List?
list.remove(index)
How do you get the size of a List?
list.size()
How do you check if a List contains an element?
list.contains(element)
How do you get an element at a specific index from a List?
list.get(index)