JAVA Methods

Test your knowledge of Java methods across String, StringBuffer, Collections, Thread, and System classes

16 Questions Published

Questions

Question 1 Multiple Choice (Single Answer)

Which of the following methods is used to extract a single character from a string?

  1. getChars()
  2. getBytes()
  3. toCharArray()
  4. charAt()
  5. equalsIgnoreCase()
Question 2 Multiple Choice (Single Answer)

The _______________ method searches for the first occurrence of a character or substring.

  1. equals()
  2. indexOf()
  3. startWith()
  4. endWith()
  5. lastIndexOf()
Question 3 Multiple Choice (Single Answer)

Which of the following methods is used to pre-allocate a space for a certain number of characters, after a StringBuffer has been constructed?

  1. setLength()
  2. length()
  3. capacity()
  4. startWith()
  5. ensureCapacity()
Question 4 Multiple Choice (Single Answer)

Which of the following methods returns the value of the invoking object as a byte?

  1. float Value()
  2. long Value()
  3. int Value()
  4. the short short Value()
  5. byte Value()
Question 5 Multiple Choice (Single Answer)

Which of the following methods is used to find the execution of the various parts of a program?

  1. arraycopy()
  2. currentTimeMillis()
  3. clone()
  4. digit()
  5. none of these
Question 6 Multiple Choice (Single Answer)

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.

  1. trim()
  2. equalsIgnoreCase()
  3. equals()
  4. indexOf()
  5. capacity()
Question 7 Multiple Choice (Single Answer)

Which of the following methods returns true, if the invoking object contains infinite values?

  1. boolean is Infinite()
  2. boolean is NaN()
  3. int hashCode()
  4. double Value()
  5. none of these
Question 8 Multiple Choice (Single Answer)

Which of the following methods returns the total number of bytes of the memory available to a program?

  1. void gc()
  2. void runFinalisation()
  3. long totalMemory()
  4. int exitValue()
  5. long freeMemory()
Question 9 Multiple Choice (Single Answer)

Which of the following methods displays the call stack for threads?

  1. void checkAccess()
  2. void destroy()
  3. void interrupt()
  4. static void dumpStack()
  5. void run()
Question 10 Multiple Choice (Single Answer)

The ___________ method determines whether the string in the question ends with a specified string or not.

  1. endWith()
  2. int hashCode()
  3. arraycopy()
  4. int exitValue()
  5. int hashCode()
Question 11 Multiple Choice (Single Answer)

If we want to convert all the characters in a String object into a character array, we use the _________ method.

  1. toCharArray()
  2. regionMatches()
  3. trim()
  4. replace()
  5. endWith()
Question 12 Multiple Choice (Single Answer)

Which of the following package methods returns the name of the invoking package?

  1. String getName()
  2. String getImplementationTitle()
  3. String getImplementationVersion()
  4. String getImplementationVendor()
  5. String getSpecificationTitle()
Question 13 Multiple Choice (Single Answer)

Which of the following interfaces enables you to work with a group of objects?

  1. Collection
  2. List
  3. Set
  4. SortedSet
  5. SecurityManager
Question 14 Multiple Choice (Single Answer)

______________ collection class extends the AbstractList for a collection that uses sequential access, rather than the random access of its elements.

  1. Abstract
  2. AbstractSequentialList
  3. AbstractList
  4. LinkedList
  5. AbstractSet
Question 15 Multiple Choice (Single Answer)

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?

  1. int activeGroupCount()
  2. final void destroy()
  3. final int getMaxPriority()
  4. int activeCount()
  5. none of these
Question 16 Multiple Choice (Single Answer)

Which of the following classes implements a dynamic array by extending the AbstractList?

  1. TreeSet
  2. ArrayList
  3. HashSet
  4. AbstractList
  5. None of these