Strings


  1. What is the string contained in s after following lines of code?
    StringBuffer str new StringBuffer("ZMania");
    str.deleteCharAt(0);











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: B

    deleteCharAt() method deletes the character at the specified index location and returns the resulting StringBuffer object.


  1. Which of this method of class String is used to extract a substring from a String object?











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: C

    substring()



  1. What is the output of this program?

    public class Result
    {
    public static void main(String args[])
    {
    String ch[] = {"p", "q", "p", "s", "t"};
    for (int K = 0; K < ch.length; ++K)
    for (int L = K + 1; L < ch.length; ++L)
    if(ch[K].compareTo(ch[L]) == 0)
    System.out.print(ch[L]);
    }
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: A

    compareTo() function returns zero when both the strings are equal, it returns a value less than zero if the invoking string is less than the other string being compared and value greater than zero when invoking string is greater than the string compared to.


  1. In the below code, which code fragment should be inserted at line 3 so that the output will be: “234pqr 234pqr”?

    1. StringBuilder strbuilder = new StringBuilder("234");
    2. String str = "234";
    3. // insert code here
    4. System.out.println(strbuilder + " " + str);











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: B

    append() is stringbuffer method and concat is String class method.
    append() is stringbuffer method and concat is String class method.



  1. What is the output of this program?

    public class Result
    {
    public static void main(String args[])
    {
    String str1 = "Hello";
    String str2 = new String(str1);
    String str3 = "HELLO";
    System.out.println(str1.equals(str2) + " " + str2.equals(str3));
    }
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: C

    true false