Java String (Hard)
30 Questions
3 Views

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to Lesson

Podcast

Play an AI-generated podcast conversation about this lesson

Questions and Answers

Which method is used to find the length of a string?

  • length() (correct)
  • charAt()
  • concat()
  • compareTo()

Which method is used to compare two strings and returns a positive value if the first string is alphabetically greater than the second string?

  • compareTo() (correct)
  • concat()
  • length()
  • charAt()

Which method is used to concatenate two strings?

  • charAt()
  • compareTo()
  • concat() (correct)
  • length()

Which method is used to find the character present at a particular index in a string?

<p>charAt() (C)</p> Signup and view all the answers

Which method is used to convert a string to upper case?

<p>toUpperCase() (A)</p> Signup and view all the answers

Which method is used to get a substring of a string?

<p>substring() (B)</p> Signup and view all the answers

Which method is used to create a formatted string in Java?

<p>format() (B)</p> Signup and view all the answers

Which class in Java is used to create and manipulate strings?

<p>String (B)</p> Signup and view all the answers

Which of the following is true about strings in Java?

<p>Strings are mutable (D)</p> Signup and view all the answers

What is the most common way of creating a Java string?

<p>Using String literals (C)</p> Signup and view all the answers

What happens when we try to create another string with the exact same value as an existing string using String literals?

<p>A reference to the existing string object is created (D)</p> Signup and view all the answers

Where are strings stored in Java?

<p>String pool (D)</p> Signup and view all the answers

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

<p>Strings cannot be modified after creation (D)</p> Signup and view all the answers

How are strings represented internally in Java?

<p>As arrays of characters (C)</p> Signup and view all the answers

Which method is used to get the substring from the beginIndex till the end of the string?

<p>substring(int beginIndex) (A)</p> Signup and view all the answers

Which method is used to get the substring from beginIndex till endIndex-1?

<p>substring(int beginIndex, int endIndex) (B)</p> Signup and view all the answers

Which method is used to check if the string contains a particular substring or not?

<p>contains(String) (C)</p> Signup and view all the answers

Which method is used for replacing all occurrences of string1 in the string with string2?

<p>replace(String1, String2) (D)</p> Signup and view all the answers

Which method is used to replace only the first occurrence of string1 with string2?

<p>replaceFirst(String1, String2) (D)</p> Signup and view all the answers

Which method is exactly like replace() and replaces all occurrences of string1 with string2?

<p>replaceAll() (B)</p> Signup and view all the answers

Which method is used for finding the index of a character or a string from a given string?

<p>indexOf(String) (B)</p> Signup and view all the answers

Which method is used to check whether a string is empty or not?

<p>isEmpty() (D)</p> Signup and view all the answers

What does the lastIndexOf() method do?

<p>Returns the index of the last occurrence of a character or string (D)</p> Signup and view all the answers

What does the hashCode() method return?

<p>The hashcode of the string (D)</p> Signup and view all the answers

What does the split() method do?

<p>Splits a string based on a delimiter/regular expression (A)</p> Signup and view all the answers

Which split() method limits the number of strings to be split based on the delimiter?

<p>String split(String, int) (A)</p> Signup and view all the answers

What does the toCharArray() method do?

<p>Converts a string to an array of characters (D)</p> Signup and view all the answers

What does the toString() method do?

<p>Converts a string to itself (A)</p> Signup and view all the answers

What does the join() method do?

<p>Joins strings together using a delimiter (C)</p> Signup and view all the answers

Which method returns the index of the first occurrence of a character or string?

<p>lastIndexOf() (D)</p> Signup and view all the answers

More Like This

Java String (Basic)
30 questions

Java String (Basic)

AwedExuberance avatar
AwedExuberance
Java String Methods Quiz
1 questions

Java String Methods Quiz

CelebratedRhodium5657 avatar
CelebratedRhodium5657
Python String Methods Quiz
5 questions
Use Quizgecko on...
Browser
Browser