Which of these method of class String is used to extract a single character from a String object? Show
(a) CHARAT() (b) chatat() (c) charAt() (d) ChatAt() I have been asked this question during an internship interview. Origin of the question is String Handling Basics topic in section String Handling of Java Select the correct answer from above options Java questions and answers, Java questions pdf, Java question bank, Java questions and answers pdf, mcq on Java pdf, Java questions and solutions, Java mcq Test , Interview Java questions, Java Questions for Interview, Java MCQ (Multiple Choice Questions),Core Java Questions, Core Java MCQ,core java interview questions for experiencedcore java interview questions for 3 years experience,java programming questions,core java interview questions for freshers,java interview questions and answers for freshers, java programming questions and answers pdf, java interview questions for beginners The Java String class substring() method returns a part of the string. We pass beginIndex and endIndex number position in the Java substring method where beginIndex is inclusive, and endIndex is exclusive. In other words, the beginIndex starts from 0, whereas the endIndex starts from 1. There are two types of substring methods in Java string. SignatureIf we don't specify endIndex, the method will return all the characters from startIndex. ParametersstartIndex : starting index is inclusive endIndex : ending index is exclusive Returnsspecified string Exception ThrowsStringIndexOutOfBoundsException is thrown when any one of the following conditions is met.
Internal implementation substring(int beginIndex)Internal implementation substring(int beginIndex, int endIndex)Java String substring() method exampleFileName: SubstringExample.java Test it NowOutput: Java String substring() Method Example 2FileName: SubstringExample2.java Output: Javatpoint point Exception in thread "main" java.lang.StringIndexOutOfBoundsException: begin 5, end 15, length 10 Applications of substring() Method1) The substring() method can be used to do some prefix or suffix extraction. For example, we can have a list of names, and it is required to filter out names with surname as "singh". The following program shows the same. FileName: SubstringExample3.java Output: Yuvraj Singh Harbhajan Singh Gurjit Singh Sandeep Singh Milkha Singh 2) The substring() method can also be used to check whether a string is a palindrome or not. FileName: SubstringExample4.java Output: madam is a palindrome. rock is not a palindrome. eye is a palindrome. noon is a palindrome. kill is not a palindrome. This is the java programming questions and answers section on "Java Strings" with an explanation for various interview, competitive examination and entrance test. Solved examples with detailed answer description, explanation are given and it would be easy to understand. Java Strings Questions
11. Which of these data type value is returned by equals() method of String class?
Answer & ExplanationAnswer: Option C Explanation: equals() method of string class returns boolean value true if both the string are equal and false if they are unequal. WorkspaceReport Error12. Which of these method of class String is used to extract a substring from a String object?
WorkspaceReport Error13. What will s2 contain after following lines of code? String s1 = "one; String s2 = s1.concat("two)
Answer & ExplanationAnswer: Option C Explanation: Two strings can be concatenated by using concat() method. Workspace
Report Error15. What is the value returned by function compareTo() if the invoking string is less than the string compared?
Answer & ExplanationAnswer: Option B Explanation: compareTo() function returns zero when both the strings are equal, it returns a value less than zero if the invoking string is less than the other string being compared and value greater than zero when invoking string is greater than the string compared to. WorkspaceReport ErrorMock Tests & Online QuizzesWhich methods of class string is used to extract a substring from a string object?You can extract a substring from a string using the slice() method.
Which of these methods of class string is used to extract a substring from a string object in Java?The substring(int start, int end) method of StringBuffer class is the inbuilt method used to return a substring start from index start and extends to the index end-1 of this sequence.
Which of this method of class 10th is used to extract a substring from a string object?split() method: The split() method of String class can be used to extract a substring from a sentence.
Which method is used to extract a part of a string?The substr() method extracts a part of a string. The substr() method begins at a specified position, and returns a specified number of characters.
|