String, String Buffers And Its Functions

25 Questions

Settings
Please wait...
String Quizzes & Trivia

Do you know what a string is? Do you have an idea of how the string and the string buffer works, not to ask the respective functions? Well, find out in the quiz below. All the best in the test and enjoy.


Questions and Answers
  • 1. 
    The method toUpperCase  and toLowerCase  will return the same string if no case conversion was needed
    • A. 

      True

    • B. 

      False

  • 2. 
    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

  • 3. 
    Which operators are overloaded for Strings?
    • A. 

      =

    • B. 

      ++

    • C. 

      +=

    • D. 

      ==

  • 4. 
    • 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

  • 5. 
     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

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

      NullCharacterException

    • B. 

      NullParameterException

    • C. 

      NullPointerException

    • D. 

      NumberFormatException

  • 7. 
    StringBuffer is faster when performing concatenation than String
    • A. 

      True

    • B. 

      False

  • 8. 
    • A. 

      Ergic th

    • B. 

      Ergic Thu

    • C. 

      Ergic Th

    • D. 

      ErgicThu

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

      5

    • B. 

      2

    • C. 

      3

    • D. 

      4

  • 10. 
    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

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

      11

    • B. 

      10

    • C. 

      14

    • D. 

      12

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

      Null

    • B. 

      Positive

    • C. 

      Negative

    • D. 

      Zero

  • 13. 
    A.hashCode() == b.hashCode() must also mean that a.equals(b)
    • A. 

      True

    • B. 

      False

  • 14. 
    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

  • 15. 
    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

  • 16. 
    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

  • 17. 
    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

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

      Multitasking

    • B. 

      Multithreading

    • C. 

      Exception handling

    • D. 

      String comparision

  • 19. 
    All operands are appended by calling toString method, if needed
    • A. 

      True

    • B. 

      False

  • 20. 
    If we override equals() , then we may or maynot override hashCode()
    • A. 

      True

    • B. 

      False

  • 21. 
    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

  • 22. 
    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

  • 23. 
    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

  • 24. 
    There is no relationship between String and StringBuffer.
    • A. 

      True

    • B. 

      False

  • 25. 
    The String class is final – its methods can’t be overloaded
    • A. 

      True

    • B. 

      False