What is the correct way to declare and initialize a String variable in Java?

Strings Java

Quiz
•
Computers
•
12th Grade
•
Hard
Manoj R
Used 1+ times
FREE Resource
16 questions
Show all answers
1.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
String str; str = 'Hello';
String str = new String('Hello');
String str = "Hello";
String str = new String(); str = 'Hello';
2.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
How can you concatenate two Strings in Java?
string1.append(string2)
string1.concat(string2)
string1 + string2
string1.add(string2)
3.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
What does the charAt method in Java return?
The length of the string
The character at the specified index
The index of the specified character
A boolean value
4.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
How can you extract a substring from a String in Java?
string.extract(startIndex, endIndex)
string.getSubstring(startIndex, endIndex)
substring.extract(startIndex, endIndex)
string.substring(startIndex, endIndex)
5.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
Which method is used to search for a specific character in a String in Java?
searchChar()
findChar()
locateChar()
indexOf()
6.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
How can you replace a specific character in a String in Java?
str.replace('a', 'b', 1);
str.replaceFirst('a', 'b');
str.replaceAll('a', 'b');
str = str.replace('a', 'b');
7.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
Which class is preferred for manipulating mutable strings in Java?
String
StringBuilder
StringBuffer
StringWriter
Create a free account and access millions of resources
Similar Resources on Quizizz
15 questions
Java Strings and Math Quiz

Quiz
•
12th Grade
20 questions
Array

Quiz
•
12th Grade
15 questions
JAVA: Level-1

Quiz
•
5th - 12th Grade
12 questions
Java - arrays and String methods

Quiz
•
9th - 12th Grade
20 questions
Arrays in Java

Quiz
•
9th - 12th Grade
16 questions
Arithmetic Types Declare Initialize Relation Logical Ops

Quiz
•
9th Grade - University
15 questions
002_Java Methods

Quiz
•
12th Grade - University
20 questions
JAVA FUNDAMENTALS

Quiz
•
9th - 12th Grade
Popular Resources on Quizizz
15 questions
Character Analysis

Quiz
•
4th Grade
17 questions
Chapter 12 - Doing the Right Thing

Quiz
•
9th - 12th Grade
10 questions
American Flag

Quiz
•
1st - 2nd Grade
20 questions
Reading Comprehension

Quiz
•
5th Grade
30 questions
Linear Inequalities

Quiz
•
9th - 12th Grade
20 questions
Types of Credit

Quiz
•
9th - 12th Grade
18 questions
Full S.T.E.A.M. Ahead Summer Academy Pre-Test 24-25

Quiz
•
5th Grade
14 questions
Misplaced and Dangling Modifiers

Quiz
•
6th - 8th Grade
Discover more resources for Computers
17 questions
Chapter 12 - Doing the Right Thing

Quiz
•
9th - 12th Grade
30 questions
Linear Inequalities

Quiz
•
9th - 12th Grade
20 questions
Types of Credit

Quiz
•
9th - 12th Grade
20 questions
Taxes

Quiz
•
9th - 12th Grade
17 questions
Parts of Speech

Quiz
•
7th - 12th Grade
20 questions
Chapter 3 - Making a Good Impression

Quiz
•
9th - 12th Grade
20 questions
Inequalities Graphing

Quiz
•
9th - 12th Grade
10 questions
Identifying equations

Quiz
•
KG - University