Strings


  1. Which of these constructors is used to create an empty String object?











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: C

    String()


  1. Which of these is an incorrect statement?











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: B

    StringBuffer class is used to create strings that can be modified after they are created.



  1. What is the output of this program?

    public class String_Example
    {
    public static void main(String args[])
    {
    char chars[] = {'I', 'L', 'U'};
    String obj = new String(chars);
    System.out.println(obj);
    }
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: A

    String(chars) is a constructor of class string, it initializes string obj with the values stored in character array chars, therefore obj contains “ILU”.


  1. What is the output of this program?

    public class String_Example
    {
    public static void main(String args[])
    {
    int ascii[] = { 80, 75, 70, 90};
    String obj = new String(ascii, 1, 3);
    System.out.println(obj);
    }
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: A

    ascii is an array of integers which contains ascii codes of Characters A, B, C, D. String(ascii, 1, 3) is an constructor which initializes obj with Characters corresponding to ascii codes stored in array ascii, starting position being given by 1 & ending position by 3, Thus s stores KFZ.



  1. What is the output of this program?

    public class String_Example
    {
    public static void main(String args[])
    {
    char chars[] = {'I', 'L', 'U'};
    String obj = new String(chars);
    String obj1 = "InterviewMania";
    int len0 = obj1.length();
    int len1 = obj.length();
    System.out.println(len0 + " " + len1);
    }
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: A

    Output: 14 3