Java String and Array
Save
Edit
Host a game
Play LiveLive
Assign HW
Solo Practice
Practice
17 QuestionsShow answers
  • Question 1
    300 seconds
    Report an issue
    Q.

    Is String a primitive data type?

    answer choices

    Yes

    No

    Both

  • Question 2
    300 seconds
    Report an issue
    Q.

    Which method to use to find length of a string?

    answer choices

    length()

    size()

    long()

    count()

  • Question 3
    300 seconds
    Report an issue
    Q.

    Which data type gets returned from length() method in String class?

    answer choices

    double

    String

    int

    number

  • Question 4
    300 seconds
    Report an issue
    Q.

    String txt = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";


    What is the correct way to find the length of "txt" string?

    answer choices

    int len = length(txt);

    float len = txt.length();

    int len = txt.length();

    double len = length(txt);

  • Question 5
    300 seconds
    Report an issue
    Q.

    Which is correct method to convert String into uppercase

    answer choices

    changeUpperCase()

    convertUpperCase()

    toUpper()

    toUpperCase()

  • Question 6
    300 seconds
    Report an issue
    Q.

    String txt = "Hello World";

    System.out.println(txt.toUpperCase());


    Choose the correct output.

    answer choices

    "HELLO WORLD"

    HELLO WORLD

    Hello world

    Hello World

  • Question 7
    300 seconds
    Report an issue
    Q.

    Choose correct purpose of indexOf() in String class.

    answer choices

    returns the index (the position) of the last occurrence of a specified text in a string

    returns the character of the first occurrence of a specified character in a string

    returns the index (the position) of the first occurrence of a specified text in a string (excluding whitespace)

    returns the index (the position) of the first occurrence of a specified text in a string (including whitespace)

  • Question 8
    300 seconds
    Report an issue
    Q.

    String x = "10";

    String y = "20";

    String z = x + y;

    System.out.println(z);

    Guess the output.

    answer choices

    1020

    10 20

    30

    "10 20"

  • Question 9
    300 seconds
    Report an issue
    Q.

    What will be the output of below code?


    String statement = "Outfit of the day";

    System.out.println(statement.Substring(3,6));

    answer choices

    it of

    tfit

    fit

    FIT

  • Question 10
    300 seconds
    Report an issue
    Q.

    Choose most appropriate purpose of trim() method in String?

    answer choices

    to remove white spaces

    to get a substring of the string

    to cut String at desired index

    to remove extra white spaces from start and end of String

  • Question 11
    300 seconds
    Report an issue
    Q.

    What is the return type of equalsIgnorecase() method?

    answer choices

    int

    String

    char

    boolean

  • Question 12
    300 seconds
    Report an issue
    Q.

    What is the most appropriate way to check if two Strings are identical?

    answer choices

    string1 == string2

    string1.equals(string2)

    string1.same(string2)

    string1.equalsIgnorecase(string2)

  • Question 13
    300 seconds
    Report an issue
    Q.

    (Multiple answer question)

    Pick all NON-primitive datatypes from below :

    answer choices

    String

    int

    primitive

    Array

  • Question 14
    300 seconds
    Report an issue
    Q.

    int[] myArray = {11, 22, 33, 44, 55};

    which code is correct to print length of above int-array?

    answer choices

    System.out.println(int[].myArray.length());

    System.out.println(myArray.length);

    System.out.println(myArray.length());

    System.out.println(int[].myArray.size());

  • Question 15
    300 seconds
    Report an issue
    Q.

    String[] friends = {"John", "Mike", "Samantha", "Monica"};

    which code is correct to print "Samantha" using array functionality?

    answer choices

    System.out.println(friends[2]);

    System.out.println(friends[3]);

    System.out.println(friends["Samantha"]);

    System.out.println(friends{2});

  • Question 16
    300 seconds
    Report an issue
    Q.

    Select correct code to create an array of "double" datatype of length 5.

    answer choices

    double arr = double[5];

    double{} arr = new double{5};

    double[5] arr = new double[];

    double[] arr = new double[5];

  • Question 17
    300 seconds
    Report an issue
    Q.

    What is the correct relation between length and last-index of array?

    answer choices

    last-index is always 1 more than the length

    last-index is 1 less than the length (but not always)

    last-index is always 1 less than the length

    last-index is always equal to the length

Report an issue
Why show ads?
Report Ad
Join a game