String, String Buffers And Its Functions Quiz

19 Questions | Total Attempts: 3714

SettingsSettingsSettings
String, String Buffers And Its Functions Quiz - Quiz

Do you know what a string is? Do you think you can pass this string, string buffers, and its functions quiz? If you have an idea of how the string and the string buffer work and their respective functions, then this quiz will be easy for you to crack. So, try this quiz and get to test your knowledge today. Wishing you all the best for this test, and enjoy.


Questions and Answers
  • 1. 
    Which operators are overloaded for Strings?
    • A. 

      =

    • B. 

      ++

    • C. 

      +=

    • D. 

      ==

  • 2. 
    Which of the following statements are false?
    • A. 

      Reverse() is available in String

    • B. 

      The content of StringBuffer can be expanded beyond their initial buffer size

    • C. 

      The standard java.lang.StringTokenizer class is a special type of Enumeration that represents segments of a string, which may be separated by one or more "delimiters"

    • D. 

      StringBuffer is a final class

    • E. 

      String objects are immutable

  • 3. 
     What will be the result if you compare StringBuffer with String if both have same values?
    • A. 

      True

    • B. 

      False

    • C. 

      Error

    • D. 

      None of these

  • 4. 
    Passing null to indexOf  or lastIndexOf will throw
    • A. 

      NullCharacterException

    • B. 

      NullParameterException

    • C. 

      NullPointerException

    • D. 

      NumberFormatException

  • 5. 
    What will be the output? String s="Synergic Thunders"; System.out.println( s.substing(4,12) );
    • A. 

      Ergic th

    • B. 

      Ergic Thu

    • C. 

      Ergic Th

    • D. 

      ErgicThu

  • 6. 
    How many overloaded constructors ,other than the default constructor, does Stringbuffer have?
    • A. 

      5

    • B. 

      2

    • C. 

      3

    • D. 

      4

  • 7. 
    What is the output of this code? String s="Now is the time for all good men"+"to come to the aid of their country"; System.out.println(s.indexOf('t')); System.out.println(s.lastIndexOf('t',10)); System.out.println(s.indexOf("the"));
    • A. 

      7,10,7

    • B. 

      8,12,8

    • C. 

      7,11,7

    • D. 

      8,11,8

  • 8. 
    Number of constructors in string object in JAVA2  v5.0 ?
    • A. 

      11

    • B. 

      10

    • C. 

      14

    • D. 

      12

  • 9. 
    If  two strings are same,the method public int compareTo returns
    • A. 

      Null

    • B. 

      Positive

    • C. 

      Negative

    • D. 

      Zero

  • 10. 
    Which of the following are used to manipulate the string buffer?
    • A. 

      Append,trim,setCharAt,and replace

    • B. 

      Append,insert,setCharAt,and reverse

    • C. 

      Append,insert,getChars,and replace

    • D. 

      Append,trim,getChars,and reverse

  • 11. 
    With respect to equals() , if x.equals(y) is true, then x.hashCode() == y.hashCode() is true. This is know as...............?
    • A. 

      Consistent

    • B. 

      Symmetric

    • C. 

      Null

    • D. 

      Reflexive

    • E. 

      Transitive

  • 12. 
    What is the output of this code? String s=”First Program”; System.out.println(“[“ + s + “]”); s.trim( );
    • A. 

      [ First Program ]

    • B. 

      [First Program]

    • C. 

      [FirstProgram]

    • D. 

      First Program

  • 13. 
    Choose the correct option.
    • A. 

      StringBuilder is synchronized, it offers faster performance than StringBuffer

    • B. 

      StringBuilder is not synchronized, it offers faster performance than StringBuffer

    • C. 

      StringBuilder is not synchronized, it offers slower performance than StringBuffer

    • D. 

      StringBuilder is synchronized, it offers slower performance than StringBuffer

  • 14. 
    In one of the cases, we must apply StringBuffer rather than StringBuilder
    • A. 

      Multitasking

    • B. 

      Multithreading

    • C. 

      Exception handling

    • D. 

      String comparision

  • 15. 
    If we override equals() , then we may or maynot override hashCode(). State true or false. 
    • A. 

      True

    • B. 

      False

  • 16. 
    What is the use of ensureCapacity()?
    • A. 

      Returns current number of capacity

    • B. 

      The string buffer is allocated atmost ‘n’ places

    • C. 

      The string buffer is allocated atleast ‘n’ places

    • D. 

      The string buffer is allocated some ‘n+1’ places

  • 17. 
    What iis the output? {             String name = "Petroleum";             System.out.println(name.equals("Petroleum"));             System.out.println(name.equals("petroleum"));             System.out.println(name.equalsIgnoreCase("petroleum"));             }
    • A. 

      True true true

    • B. 

      True false false

    • C. 

      True false true

    • D. 

      False true true

  • 18. 
    StringBuffer ab=new StringBuffer(“smith”); System.out.println(“ab = “ + ab); char charArr[ ] = “Hi xy”.tocharArray( ); Ab.getChars(0,2,charArr,3); What is the output?
    • A. 

      Hi smi

    • B. 

      Hi sm

    • C. 

      Smi

    • D. 

      Ith

  • 19. 
    String objects are immutable. what do you mean by that?
    • A. 

      A. Object state can be replaced

    • B. 

      B. Object state can’t be replaced

    • C. 

      C. Object state can’t be modified

    • D. 

      D. Object state can be modified

Back to Top Back to top