Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners String doubt replace function

Have Programming Question? Ask it here!
 
 
 


ciba kiran
String doubt replace function
2 Answer(s)      3 years and 2 months ago
Posted in : Java Beginners


What is the output and why of below :

String s1 = "Hello"; if(s1.replace('H','H')== "Hello") System.out.println("yes"); else System.out.println("No"); if(s1.replace("H", "H")== "Hello") System.out.println("yes"); else System.out.println("No");


Advertisement
View Answers

February 11, 2011 at 4:17 PM


A string cannot be compared with == operator. It is always compared with equals() function.

Compare string:

class Replace 
{
    public static void main(String[] args) 
    {
        String s1 = "Hello";
        if(s1.replace('H','H').equals( "Hello")){
            System.out.println("yes"); 
        }
        else {
            System.out.println("No");
        }
        if(s1.replace("H", "H").equals("Hello")){
            System.out.println("yes");
        }
        else{
            System.out.println("No");
        }
    }
}


February 11, 2011 at 4:29 PM


Thanks for the prompt reply. But, I understand the correct function for comparison is".equals()" and not "==". I wish to understand what is the difference when we use function replace(char old, car new) and replace("stringOld", "stringNew") which causes the above below stated output(obtained after running the code)? yes No


Related Tutorials/Questions & Answers:
String doubt replace function
String doubt replace function  What is the output and why of below : String s1 = "Hello"; if(s1.replace('H','H')== "Hello") System.out.println("yes"); else System.out.println("No"); if(s1.replace("H", "H")== "Hello
MySql find and replace string
MySql find and replace string  How to find and replace string or special characters in MySql & PHP?   Find and Replace String PHP $result = preg_replace('/\band\b/i', 'foo', $subject
Advertisements
Replace String in PHP - PHP
Replace String in PHP  What is the fastest way of replacing string in PHP Code?  Hi Friend, Please visit the following link: http://www.roseindia.net/tutorial/php/phpbasics/PHP-Array-Replace.html Thanks
MySQL Replace
; MySQL Replace function finds and replaces the occurrences of specified string...: REPLACE( String_Text, String_FROM, String_TO); where String_Text... apply this Replace function on the tables data while inserting or updating
C Replace String
C Replace String       In this section, you will learn how to replace a string in C.  Here a function pointer replace is created in which variables st, orig, repl
DOUBT ?
DOUBT ?  in c++ member function of a class must be public
Replace a String with another using "fn:replace" tag of JSTL
Replace a String with another using <fn:replace> tag of JSTL In this Section, we will replace a String with another string using <fn:replace> tag of JSTL. This tag returns a string after replacing the given sub string
doubt this
doubt this  what is the use of "this" and "super" keyword
String Function Program
String Function Program  The string function program is just an application of the string manipulation functions in JAVA. The program is designed to count the number of one-letter word, two-letter word, and three-letter words
Replace
Replace   Hi, I have two text files in two diff locatons.The text file like below using java program 1)a.txt 1 abc bangalore 2 def adfsdf 3 ghij asdfdsad 2)b.txt A B C Now i want output is like below
Doubt
Doubt  how to submit the details and how to go the next page after submitting.please clarify my doubt I don't know how to submit details
Doubt
Submit and process form  how to submit the details and how to go the next page after submitting.please clarify my doubt I don't know how to submit... LANGUAGE="JavaScript"> function getParams() { var idx = document.URL.indexOf
Doubt
User request form  how to submit the details and how to go the next page after submitting.please clarify my doubt I don't know how to submit details... LANGUAGE="JavaScript"> function getParams() { var idx = document.URL.indexOf
Doubt
How to load page  how to submit the details and how to go the next page after submitting.please clarify my doubt I don't know how to submit details... LANGUAGE="JavaScript"> function getParams() { var idx = document.URL.indexOf
Doubt
load next page after submitting  how to submit the details and how to go the next page after submitting.please clarify my doubt I don't know how...; <script LANGUAGE="JavaScript"> function getParams() { var idx
Java String : Replace All
Java String : Replace All This section defines how to replace all character... : You can replace all specific character in a given string with another character... method to replace all spaces by calling one of String method replaceAll("
Programming - Replace method
Java: Programming - Replace method Change all occurrences in a string Write a method that replaces all occurrences of one string with another. The predefined Java function replace may not be used for this -- you have to write
doubt
doubt  what is the difference between public static void main(String[] args) public static void main(String args
how to find a dynamic string in a string & how to replace tgat wth with another string - JSP-Servlet
how to find a dynamic string in a string & how to replace tgat wth... from a excel sheet specified column values and i have one string... these values into a string ,use that string to send a mail ,these 2,3,4 ,5
Replace Character in String
in a given string. To replace a character with the given character in sting first...:\replace>java Replace Your String before repalce rajesh raju raja rahul ray rani ram... Replace Character in String      
Use of <fn:replace(String, String, String)> Tag of JSTL
Use of <fn:replace(String, String, String)> Tag of JSTL...; color="green"> <c:out value="${fn:replace(string,find... : Suppose in user wants to replace all 'x' with character 'a' in string "
ereg_replace() and eregi_replace().
ereg_replace() and eregi_replace().  What is the difference between eregreplace() and eregireplace()?   Hi friends, ereg_replace() is case sensitive like "Bharat"cannot be treated as "bharat"and eregi_replace
PHP Array Replace
PHP Array Replace Sometimes we have to replace array values with given values, PHP provides array_replace() function to replace the values. array_replace... description of array_replace() is:  General Format array array
find and replace in java
find and replace in java  Need 'find and replace' function in Java to find special keyword in XMl such as @,#,!,%..and replace with their corresponding entities
Use of string-length() function in XPath
Use of string-length() function in XPath       In this section we will discuss about string-length() function in XPath. string-length() function returns the number
PHP Array Replace Recursive
PHP Array Replace Recursive: PHP provides array_replace_recursive() function to replace elements from passed arrays into the first array recursively. array_replace_recursive() replaces the values of first array with the same values from
MySQL String Function
, to_str) The REPLACE (str, from_str, to_str) function returns the String str... MySQL String Function      ... BIN (N) The BIN string function return a string value
how to write a function to print for finding the longest palindrome in the given string
how to write a function to print for finding the longest palindrome in the given string  how to write a function to print for finding the longest palindrome in the given string
Replacing String using Regularexpression
Replacing String using Regularexpression       This Example describe the way to replace a String using Regularexpression. The steps involved in replacing a String are described
Java replace all non alphanumeric
() function of String class in Java. We will use the regular expression "[^a-zA-Z0-9...Java replace all non alphanumeric  Hi, In Java how to replace all non alphanumeric characters with blank? Share me the best code for java replace
Validation doubt
have got that and implemented in my code but i have a doubt in that. As we try to put string values its not allowing to do tht it gives us message its right... think i am able to tell u what i want to and u have got whats my doubt. plz give
How ro convert char into string using recursive function in c#??
How ro convert char into string using recursive function in c#??  This coding is for java...but i want this in c# How ro convert char into string using recursive function in c#?? char [] ch={'H','E','L','L','o'}; TO ans
Replace TEXT
Replace TEXT   I have two text files in two diff locatons.The text file like below using java program 1)a.txt 1 abc bangalore 2 def adfsdf 3 ghij asdfdsad 2)b.txt A B C Now i want output is like below
Difference between translate and replace
Difference between translate and replace   hiii, What is the difference between translate and replace?   hello, Replace replace every instence of character with character sting by the given charator of string
Write a function that reads a string of digits, possibly preceded by + or -, and converts this string to the integer value it represents.
Write a function that reads a string of digits, possibly preceded... a function that reads a string of digits, possibly preceded by + or -, and converts this string to the integer value it represents. Be sure that your function
JavaScript String Function
JavaScript String Function Almost every language provides special attention towards string and string manipulation, JavaScript is no exception. It provides many built-in functions to manipulate a string.  Java String Function
PHP String Function
PHP String Function: A string is nothing but a series of characters. Most easiest way to specify the string is to enclose it in single quotes (' '... print these all. PHP String Function Example: <?php $a="
doubt on DAO's
doubt on DAO's  hai frnds.... can anyoneexplain about how to integrate struts with hibernate,any predifined plugin is available or we need to create our own plugin????? and please help me. how to use dao s while integrating
doubt on DAO's
doubt on DAO's  hai frnds.... can anyoneexplain about how to integrate struts with hibernate,any predifined plugin is available or we need to create our own plugin????? and please help me. how to use dao s while integrating
String replaceAll() Method
. This method will replace all the words in a string as shown in the output. The code... String replaceAll() Method       In this program you will learn how to replace all the words
What is the difference between ereg_replace() and eregi_replace()?
What is the difference between ereg_replace() and eregi_replace()?  What is the difference between eregreplace() and eregireplace
replace character in php
replace character in php  PHP script that replace character
big doubt
;% /* String path = request.getContextPath(); String basePath... d = new Date(); long l = d.getTime(); String query = "select... + "and broadcast_end_time<=" + l; String msg = ""; try
regexp_replace in update and replace query in postgres
regexp_replace in update and replace query in postgres  update message set data = replace (data, 'wmost','westernmost'); April 4, 2011 at 5:04 PM.... is there a way to avoid this problem. Can you send similar query using regexp_replace
Advertisements
 

 

 

DMCA.com