Two String questions

Hi!
I have two questions:
1) Can I do toString() on a null value?
2) Is there any difference in writing:
String s = new String();
and
String s;

isnt it true that in the first case s -object of
String class is created??Yes, the empty string, length zero, as he said.
>
in second case just defining a variable type String??Yes. It will either be null or have an udefined value, depending on whether it's a member variable or a method variable.

Similar Messages

  • How to compare two strings whether both are equal while ignoring the difference in special characters (example: & vs & and many others)?

    I attempted to compare two strings whether they are equal or not. They should return true if both are equal.
    One string is based on Taxonomy's Term (i.e. Term.Name) whereas other string is based on String object.
    The problem is that both strings which seem equal return false instead of true. Both string values have different special characters though their special characters are & and &
    Snapshot of different design & same symbols:
    Is it due to different culture or language?
    How to compare two strings whether both are equal while ignoring the difference in special characters (& vs &)?

    Hi Jerioon,
    If you have a list of possible ambiguous characters the job is going to be easy and if (& vs &) are the only charracters in concern awesome.
    You can use the below solution.
    Before comparing pass the variables through a replace function to standarize the char set.
    $Var = Replace($Var,"&","&")
    This is going to make sure you don't end up with ambiguous characters failing the comparison and all the char are "&" in this case.
    Similar technique is used to ignore Character Cases 'a' vs. 'A'
    Regards,
    Satyajit
    Please “Vote As Helpful”
    if you find my contribution useful or “Mark As Answer” if it does answer your question. That will encourage me - and others - to take time out to help you.

  • Comparing two strings

    How do you check to see if two strings have dashes in the same places?
    For example:
    String one= "dfsdt-ra-s-dsfd";
    String two= "dsfst-da-s-dsfd";
    would return true.
    String one="jhsdjfk-dsf-sdf"
    String two="d-dsf-dfsf-f"
    would return false.
    This is what i have:
    if (one.indexOf("-") == two.indexOf("-")) {
    return true;
    The problem with this if statement is it only checks the first time the dash come and not the whole string.
    How can I check the whole string to compare the index of string one and string two every time the dash come up.

    Hey,
    Check this code out, compile it and you should get it. Let me know if you have any questions.
    Thanks
    Riz
    public class StringCheck {
         String s1;
         String s2;
         boolean AreEqual;
         int lens1,lens2;
         public StringCheck(){
              s1="dfsdt-ra-s";
              s2="dfsdt-ra-s";
              AreEqual=false;
              lens1=s1.length();
              lens2=s2.length();
         public boolean CheckTheString(){
              boolean localcheck=false;
              if(lens1==lens2){
                   for(int i=0;i<lens1;i++){
                        if(s1.charAt(i)==s2.charAt(i)){
                             localcheck=true;
                             i++;
                        if(s1.charAt(i)!=s2.charAt(i)){
                             return false;
              if(localcheck)return true;
              else return false;
              //return true;
         public static void main(String args[]){
              StringCheck c = new StringCheck();
              boolean validate=c.CheckTheString();
              if(validate)
                   System.out.println("The string are equal");
              else
                   System.out.println("The String are not equal");
    }

  • Compare two String

    String s1 = "ABC";
    String s2 = "ABC";
    *if (s1 == s2){*     //This tests true
    *if (s1.equals(s2)){*     //This tests true
    *if (s1.equalsIgnoreCase(s2)){*//This tests true
    My understanding is s1 refers one String object with the value ("ABC"); while s2 refers another String object with the value ("ABC"); So s1 and s2 actually refers to different objects.
    Is this correct?
    If so why the above test true?
    Thanks
    Scott

    Just to dig a little further...
    For
    String s1 = "ABC";
    and
    String s1 = new String("ABC");
    You mentioned:
    if((Object)s1 == (Object)s2){
    return true;
    should return false because the two String Object references s1 and s2 are stored at different memory locations*
    --My question, the fact that the comparision of ((Object)s1 == (Object)s2){... returning  false is:
    1) because they refer to different objects which are stored ar different locations?
    OR
    2) due to the above said: two String Object references s1 and s2 are stored at different memory locations
    --I prefer the 1).  But not so sure.
    --If answer is 2),  it will contradicts in following for s1 and s2 are stored at the different locations but the comparision ((Object)s1 == (Object)s2  will return true, i.e.,
    String s1 = "ABC";
    String s2 = "ABC";
    uses String.intern at compile time
    so
    s1 reference at aaa looks for the String object at xxx
    s2 reference at bbb looks for the String object at xxx
    this way
    if((Object)s1 == (Object)s2){
    return true;
    } should return true....
    Further,
    String s1 = "abc";
    String s3 = s1;
    Now, both s1 and s3 refer to the same Object ("abc"), but s1 and s3 are stored at different locations. Yet,
    if (s1 == s3)... will return true.
    This further indicates that the comparision of two references only has something to do with the actual location of the object, not the location of the reference itself.
    Like to get your opinion on this issue.
    Thanks
    Scott

  • I got an 15 dollar iTunes card for Christmas. I took a picture of the card code to redem the card I accomplished that but when I try to download an app that cost money it asks me two security questions  that I forgot the awnsers to.what do I do?

    I got an 15 dollar iTunes card for Christmas. I took a picture of the card code to redem the card I accomplished that but when I try to download an app that cost money it asks me two security questions  that I forgot the awnsers to. Than I click the forgot security questions than it sends it to my email but that's the problem I do not get any email.

    You need to ask Apple to reset your security questions; ways of doing so include clicking here and picking a method for your country, and filling out and submitting this form.
    (96048)

  • I can't remember my two security questions on my account. I made too many attempts and got kicked out for 8 hours. I do have a back up email addy that's verified on my account as well. Any resolutions?

    Looking for some help please!  I just got an iPad 4 and tried to purchase some apps on it and was prompted to answer my Two Security Questions that are on my apple account, and I can't remember them. I do have another verified email account attached to my account besides my @me.com one.
    I created an apple account a couple years ago when I purchased my iPhone and now I can't remember what my answers were. If anyone has any suggestions or resolutions, it would be greatly appreciated as I cannot purchase anything on my new iPad and cannot make another attempt for 8 hours to my failed attempts :( Thank you

    Tomorrow call AppleCare and ask to be transferred to the account security team.

  • Hello ! When i will Buy a Movie in iTunes, they ask me two Security Questions and i have forget the 2 correct answers. Can you help me please ??

    Hello ! When i will Buy a Movie in iTunes, they ask me two Security Questions and i have forget the 2 correct answers. Can you help me please ??

    Blue, and Mr. Frisky...

  • Two previous questions may not have been as clear as I would have liked. I recently upgraded my MacBook 2008 (10.5.8) to Snow Leopard (10.6.8). With the updates came iTunes 11.1.1 and Quicktime 7.6.6. I am still using Garageband 2008 and iPhoto 2008. When

    Two previous questions may not have been as clear as I would have liked. I recently upgraded my MacBook 2008 (10.5.8) to Snow Leopard (10.6.8). With the updates came iTunes 11.1.1 and Quicktime 7.6.6. I am still using Garageband 2008 and iPhoto 2008. When I create music in Garageband I usually adjust the volume and save it. Even now when I share the Garageband created files with iTunes 11.1.1, the volime I previously set in Garageband is retained. However, when I use the music to create a slide show in iPhoto 2008 and export to Quicktime 7.6.6, the volume level I previously set is lost and seems to default to a low level. The problem seems to be either in the slide show export from iPhoto 2008 to Quicktime 7.6.6 or in Quicktime itself. Is there a work around, so that I can retain the volume level I had previously set in Garageband, a volume level that seems to transfer without problem to the new iTunes. But then iPhoto 2008 (slide show) possibly or Quicktime 7.6.6 do not cooperate. Before I did the upgrade to Snow Leopard, the new iTunes and Quicktime I had no problems with the set volume being retained in the old Quicktime. The reason I need control over the volume is that all these music files are uploaded to YouTube.

    Two previous questions may not have been as clear as I would have liked. I recently upgraded my MacBook 2008 (10.5.8) to Snow Leopard (10.6.8). With the updates came iTunes 11.1.1 and Quicktime 7.6.6. I am still using Garageband 2008 and iPhoto 2008. When I create music in Garageband I usually adjust the volume and save it. Even now when I share the Garageband created files with iTunes 11.1.1, the volime I previously set in Garageband is retained. However, when I use the music to create a slide show in iPhoto 2008 and export to Quicktime 7.6.6, the volume level I previously set is lost and seems to default to a low level. The problem seems to be either in the slide show export from iPhoto 2008 to Quicktime 7.6.6 or in Quicktime itself. Is there a work around, so that I can retain the volume level I had previously set in Garageband, a volume level that seems to transfer without problem to the new iTunes. But then iPhoto 2008 (slide show) possibly or Quicktime 7.6.6 do not cooperate. Before I did the upgrade to Snow Leopard, the new iTunes and Quicktime I had no problems with the set volume being retained in the old Quicktime. The reason I need control over the volume is that all these music files are uploaded to YouTube.

  • Is there a way to delete text between two strings?

    In Pages, is there a way to delete all text containted between two strings?
    For example, if I have a text document that looks like this:
    String 1
    String 2
    Unwanted text
    Unwanted text
    String 3
    String 4
    Is there was to delete the unwanted text between string 2 and 3 so it looks like this:
    String 1
    String 2
    String 3
    String 4
    The unwanted text is differnet between documents but string 2 and 3 are constant. I want to do this via automator for the same strings on multiple documents.
    Any help is appreciated!

    Do you mean Pages '09 v4.3?
    There were some links here:
    https://discussions.apple.com/message/24051199#24051199
    Peter

  • Problem in comparision of two strings.please help..

    I am retriving a string password from database and another string from html(user entered one).when i am printing those two strings its printing same strings.But whenever i am comparing strings and printing its not showing equal it is printing as false.what might be the reason.please help me regarding this.Thank you in advance.My cosing is as follows:
    while(rs.next())
    pwd=rs.getString("password");
    System.out.println("pmfg is..."+pwd);
    System.out.println("first string..."+pwd);
    System.out.println("second string..."+loginpwd);
    if(pwd.equals(loginpwd))
    System.out.println("true.....");
    else
    System.out.println("false....");

    once you got two string objects ......forget for where they are comming (database or html0 ....focus on those objects ....do the following
    1) use trim() function on both strings which removes the whitespaces from front and end
    2) use equalsIgnoreCase
    if the problem still persists ....then forget your code and sue the SUN people

  • Two part question 1) what happens if you  sign into messages beta on os x lion 10.7.5 after it expired? does the whole application not work or just imessage? 2) does installing messages beta on os x lion 10.7.5  delete ichat?

    Two part question
    1) what happens if you  sign into messages beta on os x lion 10.7.5 after it expired? does the whole application not work or just imessage? can you stil use AIM, jabbar, google talk, or yahoo?  if you open messages beta does it immediately tell you that messages beta expired?
    2) does installing messages beta on os x lion 10.7.5  delete ichat or just transform ichat into messages beta giving the illusion that ichat is deleted?

    Hi,
    It was never completely clear whether it was just hidden or whether Apple ran a download page for iChat 6.
    As the Download for Messages Beta was separate and "Deleted" iChat it would seem it would be another download for iChat 6.
    iMessages will not function as it is only an Account type within Messages and iChat 6 does not have it.
    Therefore messages on the iPhone will not sync to the Mac. (until you get Mountain Lion and Messages in that OS X version).
    Mountain Lion and it's full version of Messages will not sync the iMessages that have happened in between the 14th December 2012  (end date of Messages beta) and the Install of Mountain Lion if you decide on that route.
    8:51 PM      Sunday; May 5, 2013
      iMac 2.5Ghz 5i 2011 (Mountain Lion 10.8.3)
     G4/1GhzDual MDD (Leopard 10.5.8)
     MacBookPro 2Gb (Snow Leopard 10.6.8)
     Mac OS X (10.6.8),
     Couple of iPhones and an iPad
    "Limit the Logs to the Bits above Binary Images."  No, Seriously

  • How to Compare two strings in PL/SQL

    Hi All,
    I need to compare two strings whether they are equal or not in PL/SQL.Is there any function to comparing the strings.

    Yes, the = sign.
    Are you after something like:
    IF v_string1 = v_string2 THEN
    ELSE
    END IF;?
    Edited by: Boneist on 27-Aug-2009 11:41

  • Compare two string in different line in textarea

    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class TextCounterPanel extends JPanel {
    private JTextArea textInput;
    private JLabel lineCountLabel;
                        public TextCounterPanel() {
                        setBackground(Color.DARK_GRAY);
                        textInput = new JTextArea();
                        textInput.setBackground(Color.WHITE);
                        JPanel south = new JPanel();
                        south.setBackground(Color.DARK_GRAY);
                        south.setLayout( new GridLayout(4,1,2,2) );
                             JButton countButton = new JButton("Process the Text");
                             countButton.addActionListener( new ActionListener() {
                                  public void actionPerformed(ActionEvent evt) {
                                       processInput();
                             south.add(countButton);
                        lineCountLabel = new JLabel(" Number of lines:");
                        lineCountLabel.setBackground(Color.WHITE);
                        lineCountLabel.setForeground(Color.BLUE);
                        lineCountLabel.setOpaque(true);
                        south.add(lineCountLabel);
                        setLayout( new BorderLayout(2,2) );
                        setBorder(BorderFactory.createLineBorder(Color.DARK_GRAY));
                        JScrollPane scroller = new JScrollPane( textInput );
                        add(scroller, BorderLayout.CENTER);
                        add(south, BorderLayout.SOUTH);
    public void processInput() {
    String text,vin; // The user's input from the text area.
    text = textInput.getText();
    vin =text.substring(25,42);
    lineCountLabel.setText(" vin: " + vin);
    } // end class TextCounterPanel
    How can I compare two string in different line in text area

    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class TextCounterPanel extends JPanel {
    private JTextArea textInput;
    private JLabel lineCountLabel;
    public TextCounterPanel() {
    setBackground(Color.DARK_GRAY);
    textInput = new JTextArea();
    textInput.setBackground(Color.WHITE);
    JPanel south = new JPanel();
    south.setBackground(Color.DARK_GRAY);
    south.setLayout( new GridLayout(4,1,2,2) );
    JButton countButton = new JButton("Process the Text");
    countButton.addActionListener( new ActionListener() {
    public void actionPerformed(ActionEvent evt) {
    processInput();
    south.add(countButton);
    lineCountLabel = new JLabel(" Number of lines:");
    lineCountLabel.setBackground(Color.WHITE);
    lineCountLabel.setForeground(Color.BLUE);
    lineCountLabel.setOpaque(true);
    south.add(lineCountLabel);
    setLayout( new BorderLayout(2,2) );
    setBorder(BorderFactory.createLineBorder(Color.DARK_GRAY));
    JScrollPane scroller = new JScrollPane( textInput );
    add(scroller, BorderLayout.CENTER);
    add(south, BorderLayout.SOUTH);
    public void processInput() {
    String text,vin; // The user's input from the text area.
    text = textInput.getText();
    vin =text.substring(25,42);
    lineCountLabel.setText(" vin: " + vin);
    } // end class TextCounterPanel

  • Compare two strings in a formula

    Hi,
    I'd like to know if there's a way to compare two strings in a formula ?
    I have this consition:
    IF(@SUBSTRING(@NAME(@CURRMBR(TIME_FROM)),5)==@NAME(@CURRMBR(TIME)))
    But the == operator can only compare two data.
    Thanks,
    Cyril

    Hi,
    thank you both for your answers.
    When I figured that the == operator was for data only, I didn't even try to compare member names.
    I finally used the solution that Cameron suggested in another conversation. I created a date measure, and loaded some data since the beginning of my time to the end.
    It starts in 1974 (annually), then becomes monthly data, and then daily data from 2009, so it's not so many blocks to br created. In the end I have the same value for "from 2008"/"from Apr 30", and I can easily compare my dates.
    Note that I could have also used the @TODATE function, which turns a date into a number, but the format of date is limited and doesn't fit the format of my member names, so I got lasy... and I'm not sure my users would have apreciated that ;)
    Thanks, this post is solved.
    Cyril

  • Two theoretical questions

    Hi there!
    I'm designing an authentication system. Two theoretical questions have evolved. I am not so sure about it. Hope you can help me out =)
    1. First sign or first cipher?
    What is best practice here? Is it a risk to a symmetrical cryptosystem, if there's also a hash of the plaintext available? Or should the cipher text be signed? I am afraid that this might cause a security risk for the hash: The ciphertext's entropy should be lower than the plaintext's, which might cause lower entropy of the hash value that makes it more likely to find possible collusions.
    2. Challenge Response Authentication
    This is an hypotectical one: Is it of matter, if a (one-side) Challenge Response Authentication is done reverse: Bob sends Alice f(RAND), Alice deciphers it and sends RAND back to Bob.
    Thanks for your help!

    ManuelBreu wrote:
    I'm sorry, my questions were not precise: By entropy I meant the ciphertext's nature that 0 and 1 will have (almost) the same likeliness, which is not the case in the plaintext. This depends very much on the nature of the cleartext. If your cleartext is alpha numeric ASCII then it is certain that the most significant bit of any byte will be a zero with some bias in the other bits (I have never looked at it so I don't know to what extent).
    But you are right: I am affraid, that the uncertainty of the key might be negatively affected by fact, that there is also a hashvalue of the plaintext available.The extra information in the form of the hash means that there is less uncertainty but I would take the resultant entropy as near to the minimum of(hash entropy, key entropy, cleartext entropy).

Maybe you are looking for