Strings


  1. Which of this method of class String is used to obtain a length of String object?











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: B

    Method length() of string class is used to get the length of the object which invoked method length().


  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[])
    {
    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


  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 stringClass_Example
    {
    public static void main(String args[])
    {
    String str = "Interview";
    String str1 = "Mania";
    String str2 = str;
    str2 = " Mania";
    System.out.println(str + " " + str2);
    }
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: D

    Interview Mania