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()</p> Signup and view all the answers

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

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

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

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

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

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

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

    <p>String</p> Signup and view all the answers

    Which of the following is true about strings in Java?

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

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

    <p>Using String literals</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</p> Signup and view all the answers

    Where are strings stored in Java?

    <p>String pool</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</p> Signup and view all the answers

    How are strings represented internally in Java?

    <p>As arrays of characters</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)</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)</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)</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)</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)</p> Signup and view all the answers

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

    <p>replaceAll()</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)</p> Signup and view all the answers

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

    <p>isEmpty()</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</p> Signup and view all the answers

    What does the hashCode() method return?

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

    What does the split() method do?

    <p>Splits a string based on a delimiter/regular expression</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)</p> Signup and view all the answers

    What does the toCharArray() method do?

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

    What does the toString() method do?

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

    What does the join() method do?

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

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

    <p>lastIndexOf()</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