JAVA Methods
Test your knowledge of Java methods across String, StringBuffer, Collections, Thread, and System classes
Questions
Which of the following methods is used to extract a single character from a string?
- getChars()
- getBytes()
- toCharArray()
- charAt()
- equalsIgnoreCase()
The _______________ method searches for the first occurrence of a character or substring.
- equals()
- indexOf()
- startWith()
- endWith()
- lastIndexOf()
Which of the following methods is used to pre-allocate a space for a certain number of characters, after a StringBuffer has been constructed?
- setLength()
- length()
- capacity()
- startWith()
- ensureCapacity()
Which of the following methods returns the value of the invoking object as a byte?
- float Value()
- long Value()
- int Value()
- the short short Value()
- byte Value()
Which of the following methods is used to find the execution of the various parts of a program?
- arraycopy()
- currentTimeMillis()
- clone()
- digit()
- none of these
The _________ method is used to perform a comparison that ignores the case differences, i.e. it considers A - Z to be the same as a - z.
- trim()
- equalsIgnoreCase()
- equals()
- indexOf()
- capacity()
Which of the following methods returns true, if the invoking object contains infinite values?
- boolean is Infinite()
- boolean is NaN()
- int hashCode()
- double Value()
- none of these
Which of the following methods returns the total number of bytes of the memory available to a program?
- void gc()
- void runFinalisation()
- long totalMemory()
- int exitValue()
- long freeMemory()
Which of the following methods displays the call stack for threads?
- void checkAccess()
- void destroy()
- void interrupt()
- static void dumpStack()
- void run()
The ___________ method determines whether the string in the question ends with a specified string or not.
- endWith()
- int hashCode()
- arraycopy()
- int exitValue()
- int hashCode()
If we want to convert all the characters in a String object into a character array, we use the _________ method.
- toCharArray()
- regionMatches()
- trim()
- replace()
- endWith()
Which of the following package methods returns the name of the invoking package?
- String getName()
- String getImplementationTitle()
- String getImplementationVersion()
- String getImplementationVendor()
- String getSpecificationTitle()
Which of the following interfaces enables you to work with a group of objects?
- Collection
- List
- Set
- SortedSet
- SecurityManager
______________ collection class extends the AbstractList for a collection that uses sequential access, rather than the random access of its elements.
- Abstract
- AbstractSequentialList
- AbstractList
- LinkedList
- AbstractSet
Which of the following thread group methods returns the number of threads in a group, along with the group, for which this thread is a parent?
- int activeGroupCount()
- final void destroy()
- final int getMaxPriority()
- int activeCount()
- none of these
Which of the following classes implements a dynamic array by extending the AbstractList?
- TreeSet
- ArrayList
- HashSet
- AbstractList
- None of these