I have a String s = java; What is the output when I say
s.replaceAll('j', 'k'); Also what is the value of s after
replacing?
Answers were Sorted based on User's Feedback
Answer / vikneswarank
String s="java";
s.repalce('j','k');
System.out.println(s);
output is: java
because String is immutable.we cannt change of string
content.suppose u have to write
s=s.repalce('j','k');
output is :kava
| Is This Answer Correct ? | 24 Yes | 3 No |
Answer / pradeep rout
public class Test {
public static void main(String args[])
{
String s="java";
System.out.println("Before>>>>>>>"+s);
s=s.replaceAll("j", "k");
System.out.println("After>>>>>>>"+s);
}
}
----------------------Output---------
Before>>>>>>>java
After>>>>>>>kava
| Is This Answer Correct ? | 11 Yes | 1 No |
Answer / puneet
No, the strings are immutable; the value of s will be the
same but new object kava will get crated which wil have no
refrence. s will refer to the same object which is not
changed.
s=s.replace("",""); should have worked...otherways
| Is This Answer Correct ? | 4 Yes | 2 No |
Answer / malli
Compile time error error.
String s=java here double quotes missing
and s.replaceAll('j','k'); here also we have to give double quotes.
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / prachi
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
The method replaceAll(String, String) in the type String is not applicable for the arguments (char, char)
will be thrown because in replaceAll(‘j’,’k’) : j & k are in single quote which defines as character not as string. For correct output first replace single quote with double quotes and second write s = s.replaceAll(“j”, “k”);
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / prabhavith
replaceAll take two strings as parameter
but in the given question characters are given as parameter
hence it is an error
| Is This Answer Correct ? | 5 Yes | 6 No |
Answer / nikhil hegde
when u say s.replaceAll('j','k') their will be no output but
internally the string s will be stored as kava. so when u
ask for the output the output will be kava
| Is This Answer Correct ? | 3 Yes | 5 No |
What is a parameter in matrices?
Is break statement can be used as labels in java?
What is java in detail?
How can I debug the Java security exceptions and AccessControlExceptions?
In what ways you can handle exception ?
Why do we need public static void main(String args[]) method in Java...?
How do you create a method in java?
What are the differences between getting and load method?
Hi Every One I Have Small Doubt Please answer This???????????????????????????? I Want to use AbstractList class methods(java.util.AbstractList) My Program is import java.util.*; class DemoOne extends AbstractList { public static void main(String[] args) { AbstractList a=new DemoOne();//This One is Correct?? DemoOne a1=new DemoOne();//This One is Correct?? Both Are Not Working System.out.println("Hello World!"+a); System.out.println("Hello World!"+a1); } } Error IS: DemoOne.java:2: DemoOne is not abstract and does not override abstract method get(int) in java.util.AbstractList class DemoOne extends AbstractList AnyOne can Please Provide The Solution????????????????????????? Plzzzzzzz
What is Locale class?
What are heap memory and stack memory and what are memory tables.
Explain about sets?