Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


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



I have a String s = java; What is the output when I say s.replaceAll('j', 'k');..

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

I have a String s = java; What is the output when I say s.replaceAll('j', 'k');..

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

I have a String s = java; What is the output when I say s.replaceAll('j', 'k');..

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

I have a String s = java; What is the output when I say s.replaceAll('j', 'k');..

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

I have a String s = java; What is the output when I say s.replaceAll('j', 'k');..

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

I have a String s = java; What is the output when I say s.replaceAll('j', 'k');..

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

I have a String s = java; What is the output when I say s.replaceAll('j', 'k');..

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

I have a String s = java; What is the output when I say s.replaceAll('j', 'k');..

Answer / savita

kava

Is This Answer Correct ?    0 Yes 3 No

Post New Answer

More Core Java Interview Questions

Why is java called java?

0 Answers  


What is math in java?

0 Answers  


What is the difference between Grid and Gridbaglayout?

0 Answers  


How multipleInheritance is possible in java?

18 Answers   Satyam,


What is the purpose of the system class in java?

0 Answers  


What is early binding and late binding in java?

0 Answers  


What is an error in java?

0 Answers  


hr interview how many minutes asking question

0 Answers  


What is jdbc api?

0 Answers  


FOR EXAMPLE WE R HAVING TWO LIST ELEMENTS ..BOTH LISTS CONTAINS ID,NAME,PLACE ..I NEED TO COMPARE BOTH IDS IN TWO LISTS,IF ID'S R SAME MEANS WE HAVE ADD THE DETAILS(LIKE NAME,PLACE) TO MAP...HOW IS POSSIBLE ?CAN ANY ONE SUGGEST?

1 Answers  


Can a final variable be initialized in constructor?

0 Answers  


What is difference between throw and throws ?

0 Answers   Cyient,


Categories