Which class is used to work with strings in Java?
A
String B
Strings C
Text D
Char
Analysis & Theory
Java uses the `String` class to create and manipulate strings.
What is the output of:
`System.out.println("Hello" + " World");`
A
HelloWorld B
Hello World C
Hello + World D
Hello
Analysis & Theory
The `+` operator concatenates the strings, so the output is `Hello World`.
Are strings mutable in Java?
A
Yes B
No C
Only in some cases D
Depends on JVM
Analysis & Theory
Strings in Java are immutable. Once created, they cannot be changed.
What does the method `length()` do?
A
Returns number of characters B
Returns size in bytes C
Returns last character D
Returns index of a character
Analysis & Theory
`length()` returns the number of characters in a string.
How do you compare two strings in Java for equality?
A
str1 == str2 B
str1.equals(str2) C
equals(str1, str2) D
compare(str1, str2)
Analysis & Theory
`equals()` compares the content of two strings.
What will the output be?
`String s = "Java"; System.out.println(s.charAt(2));`
A
J B
a C
v D
Error
Analysis & Theory
`charAt(2)` gives the character at index 2, which is `'v'`.
Which method changes all characters in a string to uppercase?
A
toUpper() B
makeUpperCase() C
upperCase() D
toUpperCase()
Analysis & Theory
`toUpperCase()` converts all letters in a string to uppercase.
What does `substring(1, 4)` return from `"Programming"`?
A
Prog B
rog C
rogra D
rog
Analysis & Theory
`substring(1, 4)` returns characters from index 1 to 3: `'rog'`.
What is the result of:
`"abc".equals("ABC")`?
A
true B
false C
error D
null
Analysis & Theory
String comparison is case-sensitive in Java. So `'abc'` ≠ `'ABC'`.
Which method checks if a string contains another substring?
A
has() B
contains() C
includes() D
match()
Analysis & Theory
`contains()` checks if a string contains a specific sequence of characters.