Computer Applications
Given the code :
String s = new String("abc");
Which of the following calls are invalid ?
- s.trim( )
- s.replace('a', 'A')
- s.substring(3)
- s.toUpperCase( )
- s.setCharAt(1, 'A')
Java String Handling
7 Likes
Answer
s.setCharAt(1, 'A')
Reason — setCharAt() is a method of StringBuffer class. It cannot be used with a String object, which is immutable.
Answered By
4 Likes
Related Questions
Given the code
String s1 = "yes" ; String s2 = "yes" ; String s3 = new String(s1) ;Which of the following would equate to False ?
- s1 == s2
- s3 == s1
- s1.equals(s2)
- s3.equals(s1)
Suppose that s1 and s2 are two strings. Which of the statements or expressions are incorrect ?
- String s3 = s1 + s2;
- String s3 = s1 - s2;
- s1.compareTo(s2);
- int m = s1.length( );
Which of these class is superclass of String and StringBuffer class?
- java.util
- java.lang
- ArrayList
- None of the mentioned
Which of these methods of class String is used to obtain length of String object?
- get( )
- Sizeof( )
- lengthof( )
- length( )