Software Development Exam  >  Software Development Tests  >  Basics of Java  >  Test: Strings - 2 - Software Development MCQ

Test: Strings - 2 - Software Development MCQ


Test Description

15 Questions MCQ Test Basics of Java - Test: Strings - 2

Test: Strings - 2 for Software Development 2024 is part of Basics of Java preparation. The Test: Strings - 2 questions and answers have been prepared according to the Software Development exam syllabus.The Test: Strings - 2 MCQs are made for Software Development 2024 Exam. Find important definitions, questions, notes, meanings, examples, exercises, MCQs and online tests for Test: Strings - 2 below.
Solutions of Test: Strings - 2 questions in English are available as part of our Basics of Java for Software Development & Test: Strings - 2 solutions in Hindi for Basics of Java course. Download more important topics, notes, lectures and mock test series for Software Development Exam by signing up for free. Attempt Test: Strings - 2 | 15 questions in 30 minutes | Mock test for Software Development preparation | Free important questions MCQ to study Basics of Java for Software Development Exam | Download free PDF with solutions
Test: Strings - 2 - Question 1

Which of the following statements about strings in Java is true?

Detailed Solution for Test: Strings - 2 - Question 1

Strings in Java are implemented as objects of the 'String' class, which internally represents them as arrays of characters.

Test: Strings - 2 - Question 2

What will be the output of the following code?
String str1 = "Hello";
String str2 = new String("Hello");
System.out.println(str1 == str2);

Detailed Solution for Test: Strings - 2 - Question 2

The '==' operator compares the memory addresses of two objects. In this case, 'str1' and 'str2' refer to different string objects, so the result will be false.

1 Crore+ students have signed up on EduRev. Have you? Download the App
Test: Strings - 2 - Question 3

Which of the following methods is used to concatenate two strings in Java?

Detailed Solution for Test: Strings - 2 - Question 3

The 'concat()' method is used to concatenate two strings in Java. For example, 'str1.concat(str2)' will concatenate 'str2' to the end of 'str1'.

Test: Strings - 2 - Question 4

What will be the output of the following code?
String str = "Java";
str.toUpperCase();
System.out.println(str);

Detailed Solution for Test: Strings - 2 - Question 4

The 'toUpperCase()' method returns a new string with all characters converted to uppercase. However, the original string 'str' remains unchanged. Therefore, the output will be "java".

Test: Strings - 2 - Question 5

Which of the following methods is used to determine the length of a string in Java?

Detailed Solution for Test: Strings - 2 - Question 5

The 'length()' method is used to determine the length of a string in Java. For example, 'str.length()' will return the number of characters in the string 'str'.

Test: Strings - 2 - Question 6

What will be the output of the following code?
String str = "Hello,World";
String[] tokens = str.split(",");
System.out.println(tokens.length);

Detailed Solution for Test: Strings - 2 - Question 6

The 'split()' method is used to split a string into an array of substrings based on a delimiter. In this case, the delimiter is "," (comma), so the string will be split into two tokens: "Hello" and "World".

Test: Strings - 2 - Question 7

What will be the output of the following code?
String str = "Hello,World";
String[] tokens = str.split(",");
System.out.println(tokens[0]);

Detailed Solution for Test: Strings - 2 - Question 7

The 'split()' method divides the original string into substrings at the specified delimiter. In this case, the first token is "Hello", which is stored at index 0 of the 'tokens' array.

Test: Strings - 2 - Question 8

What will be the output of the following code?
String str = "Hello,World";
String[] tokens = str.split(",");
System.out.println(tokens[1]);

Detailed Solution for Test: Strings - 2 - Question 8

The 'split()' method divides the original string into substrings at the specified delimiter. In this case, the second token is "World", which is stored at index 1 of the 'tokens' array.

Test: Strings - 2 - Question 9

What will be the output of the following code?
String str = "Hello, World";
String[] tokens = str.split("\\s+");
System.out.println(tokens[0]);

Detailed Solution for Test: Strings - 2 - Question 9

The 'split()' method splits the original string into substrings based on one or more whitespace characters. In this case, the first token is "Hello", which is stored at index 0 of the 'tokens' array.

Test: Strings - 2 - Question 10

What will be the output of the following code?
String str = "Java Programming";
String result = str.replace("Java", "Python");
System.out.println(result);

Detailed Solution for Test: Strings - 2 - Question 10

The 'replace()' method replaces all occurrences of a specified substring with another substring. In this case, "Java" is replaced with "Python", resulting in the string "Python Programming".

Test: Strings - 2 - Question 11

What will be the output of the following code?
String str = "CodeChef";
String result = "";
for (int i = str.length() - 1; i >= 0; i--)
    result += str.charAt(i);
System.out.println(result);

Detailed Solution for Test: Strings - 2 - Question 11

The given code reverses the string "CodeChef" character by character and stores the result in the variable 'result'. The output will be "fehCedoC".

Test: Strings - 2 - Question 12

What will be the output of the following code?
String str = "Hello, World";
String result = str.substring(7, 12);
System.out.println(result);

Detailed Solution for Test: Strings - 2 - Question 12

The 'substring()' method returns a new string that is a substring of the original string. In this case, the substring from index 7 to 11 (excluding the character at index 12) is "World".

Test: Strings - 2 - Question 13

What will be the output of the following code?
String str = "Hello";
String result = str.replace("l", "L");
System.out.println(result);

Detailed Solution for Test: Strings - 2 - Question 13

The 'replace()' method replaces all occurrences of a specified substring with another substring. In this case, "l" is replaced with "L", resulting in the string "HeLLo".

Test: Strings - 2 - Question 14

What will be the output of the following code?
String str = "Hello";
String result = str.substring(1, 4);
System.out.println(result);

Detailed Solution for Test: Strings - 2 - Question 14

The 'substring()' method returns a new string that is a substring of the original string. In this case, the substring from index 1 to 3 (excluding the character at index 4) is "Hell".

Test: Strings - 2 - Question 15

What will be the output of the following code?
String str = "OpenAI";
String result = str.substring(0, 2) + str.substring(3);
System.out.println(result);

Detailed Solution for Test: Strings - 2 - Question 15

The 'substring()' method returns a new string that is a substring of the original string. In this case, the substring from index 0 to 1 (excluding the character at index 2) is "Op", and the substring from index 3 to the end is "AI". The two substrings are concatenated to form the string "OpAI".

60 videos|37 docs|12 tests
Information about Test: Strings - 2 Page
In this test you can find the Exam questions for Test: Strings - 2 solved & explained in the simplest way possible. Besides giving Questions and answers for Test: Strings - 2, EduRev gives you an ample number of Online tests for practice

Top Courses for Software Development

60 videos|37 docs|12 tests
Download as PDF

Top Courses for Software Development