String equals and == difference...

Hi all

According to my understanding is equal to string corresponds to the string value and 'is' corresponds to objects represented on each side of the operator. but I saw a strange behavior while playing with these String API.

class StringTest1
{
Public Shared Sub main (String [] args)
{
Ja string = "Ja".
String's = "go";

Java2 string = "Java";
String java1 = ja + is going;
String java1 = "Java";

System.out.println ("is equal to:" + (java1.equals (java2)));
System.out.println ("==:" + (java1 is java2));
}
}

For the code above I get the output as 'true' for the first and 'false' for the second expression. output equal to equal is fair enough, but for the operator "is" its fake giving that according to my thinking should be true as says the chain worn No. TWO CHANNELS WITH SAME VALUES funda.
Among the 2 variables java2 is a string 'Java' and java1 is the result of the concatenation smthing like 'Ja' + 'goes '.

I tried to do something like
System.out.println ("obj1:" + java1.hashCode ());
System.out.println ("obj1:" + java2.hashCode ());
BTU that returns the same value.

Please help me understand how is the expression be false for "is".

Published by: 807216 on May 10, 2011 02:20

For comparison, try to "ja" and "goes" final.

final String ja = "Ja";
final String va = "va";

String java2 = "Java";
String java1 = ja + va;
//String java1 = "Java";

System.out.println("equals: " + (java1.equals(java2)));
System.out.println("==: " + (java1 == java2));

prints

equals: true
==: true

This is because "ja + is going" is a constant expression and can be evaluated by the compiler.

Tags: Java

Similar Questions

  • By comparing the dynamic fields of objects using equals and hashCode methods

    To compare the different objects of the same class with their content as jobTitleId, classificationId, deptId & classificationId had to be done and do a few steps later, using Set and the map. I was able to do it by simple substitution of equals and hashCode methods of the object class and was able to read the information (as in the map below).

    Map < LocationData, list < LocationData > >

    The following is the class I used (its been shown you so that it can be called for my problem statement):

    Class LocationData

    package com.astreait.bulkloader;

    public class LocationData {}

    String locId, deptId, jobTitleId, classificationId;

    @Override

    public boolean equals (Object obj) {}

    LocationData ld = (LocationData) obj;

    return this.deptId.equals (ld.deptId) & & this.jobTitleId.equals (ld.jobTitleId) & & this.classificationId.equals (ld.classificationId) & &

    this.locId.equals (ld.locId);

    }

    @Override

    public int hashCode() {}

    return deptId.hashCode () + jobTitleId.hashCode () + classificationId.hashCode () + locId.hashCode ();

    }

    }

    Problem:

    I am already known to which all the fields of this object, I need to make the comparison.

    IE I have to use the variables named classificationId, deptId, jobTitleId & locId etc.

    Need:

    I need to customize this logic such as names (classificationId, deptId, jobTitleId & locId etc.) fields can be learned, dynamically, as well as their values. So, as far as I understand, I've made use of 2 classes (TableClass and ColWithData), such as the list of the ColWithData is there in the TableClass object.

    I think what will happen if I substitute the same two methods "equals() and hashCode();"

    as the same thing is possible.

    TableClass class #1

    Class TableClass {}

    The list < ColWithData > cwdList;

    @Override

    public boolean equals (Object obj) {}

    Return Boolean = false;

    I need to have the logic must be set such that

    all dynamic fields can be compared

    return return;

    }

    @Override

    public int hashCode() {}

    Return int = 0;

    I need to have the logic must be set such that

    All dynamic fields for their individual codes can be found

    return return;

    }

    }

    ColWithData class #2

    Class ColWithData {}

    Pass the string; Here, the jobTitleId, classificationId, deptId, locId or any other information fields more may come.

    String data; The corresponding data or value for each jobTitleId, classificationId, deptId, locId or any other more fields.

    }

    Please let me know if I'm the procedure in the right direction or should I do a different approach. If it is allowed to use the current approach then what should be done to equals and hashCode methods?

    Finally, I need to make the map as: (is not worried how I give you, but may be considered my goal sought this logic)

    Map < TableClass, list < TableClass > > finalMap;

    I'm sorry for that. Although the problem is resolved, on my side.

  • Best way to transfer strings, arrays and clusters

    Hi, I just want to know the best way to transfer strings, arrays and clusters between a PC and a computer-RT (compactRIO) if I want to use them in deterministic loops:

    For a string should I use a published network shared variable flow or network?

    For an array of doubles should I flatten the array in a string and the string of transfer? or should I send it as a picture?

    The same for clusters, should I flatten the cluster or the transfer as a cluster?

    Thank you!

    Transfers on the network are not deterministic.  You ask how to use the data in a deterministic way, once it arrives on the RT system.  Usually, you would create a separate loop, not critics of time to deal with network communications.  The data arrives it is copied in real-time-safe structures such as RT-FIFO to put at the disposal of the evanescent loop.

    I can't give you specific advice on network variables and network flows; Finally, I did this kind of transfer over TCP, until these other options were available.

  • Similarities and differences in Windows 7, 8 and 10

    I'm doing research for my book on the similarities and differences between Windows 7, Windows 8 and Windows 10. I want to know what makes 10 if large amongst the rest and that lack of windows 7 and 8. I want to know exactly where I can find this information for reference purposes.

    Hello

    I'm sorry, but we are here to help posters with their computer problems, only not to do homework, assignments, etc.

    And the only way to learn is to do the research yourself.

    I suggest that you use your favorite search engine (Google, Bing, etc.).

    Kind regards.

  • could not find a server reports and analysis hyperion running on localhost port 6800. Please check your connection string server and verify that the server is

    Hi all

    We have properly installed and configured Hyperion Reporting and analysis 11.1.2.4 in windows 2012 server however when I try to logint to the workspace, I get an error like "start-up of the specified document does not exist in the repository." "Select a new start under the General Preferences tab document" monitoring of "could not find a server reports and analysis hyperion running on localhost at port 6800. Please check your connection string server and verify that the server is up '.



    10.PNG


    11.PNG

    HyS9RaFramework_epmsystem2-syserr:

    GsmNotFound

    com.brio.one.services.globalservicemanager.GSMException: GsmNotFound

    at com.brio.one.services.globalservicemanager.GSMFactory.getGSM (unknown Source)

    to com.brio.one.client.ClientFactory. < init >(Unknown Source)

    to com.brio.one.client.ClientFactory. < init >(Unknown Source)

    to com.brio.one.client.ClientFactory$ ClientFactoryInitializer.connect (unknown Source)

    at com.brio.one.client.ClientFactory.getClientFactoryConnect (unknown Source)

    at com.brio.one.client.ClientFactory.getDefaultGSM (unknown Source)

    at com.brio.one.web.properties.ApplicationProperties.getDefaultGSM (unknown Source)

    at com.brio.one.web.properties.ApplicationProperties.getDefaultGSMContext (unknown Source)

    at com.sqribe.WS.WSBaseServlet.setDefaultGSMContext (unknown Source)

    at com.sqribe.WS.WSBaseServlet.initLogging (unknown Source)

    at com.sqribe.WS.WSBaseServlet.loadConfiguration (unknown Source)

    at com.sqribe.WS.WSBaseServlet.init (unknown Source)

    to weblogic.servlet.internal.StubSecurityHelper$ ServletInitAction.run (StubSecurityHelper.java:283)

    at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)

    at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:120)

    at weblogic.servlet.internal.StubSecurityHelper.createServlet(StubSecurityHelper.java:64)

    at weblogic.servlet.internal.StubLifecycleHelper.createOneInstance(StubLifecycleHelper.java:58)

    to weblogic.servlet.internal.StubLifecycleHelper. < init > (StubLifecycleHelper.java:48)

    at weblogic.servlet.internal.ServletStubImpl.prepareServlet(ServletStubImpl.java:539)

    at weblogic.servlet.internal.WebAppServletContext.preloadServlet(WebAppServletContext.java:1981)

    at weblogic.servlet.internal.WebAppServletContext.loadServletsOnStartup(WebAppServletContext.java:1955)

    at weblogic.servlet.internal.WebAppServletContext.preloadResources(WebAppServletContext.java:1874)

    at weblogic.servlet.internal.WebAppServletContext.start(WebAppServletContext.java:3155)

    at weblogic.servlet.internal.WebAppModule.startContexts(WebAppModule.java:1518)

    at weblogic.servlet.internal.WebAppModule.start(WebAppModule.java:487)

    to weblogic.application.internal.flow.ModuleStateDriver$ 3.next(ModuleStateDriver.java:427)

    at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:52)

    at weblogic.application.internal.flow.ModuleStateDriver.start(ModuleStateDriver.java:119)

    at weblogic.application.internal.flow.ScopedModuleDriver.start(ScopedModuleDriver.java:201)

    at weblogic.application.internal.flow.ModuleListenerInvoker.start(ModuleListenerInvoker.java:249)

    to weblogic.application.internal.flow.ModuleStateDriver$ 3.next(ModuleStateDriver.java:427)

    at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:52)

    at weblogic.application.internal.flow.ModuleStateDriver.start(ModuleStateDriver.java:119)

    at weblogic.application.internal.flow.StartModulesFlow.activate(StartModulesFlow.java:28)

    to weblogic.application.internal.BaseDeployment$ 2.next(BaseDeployment.java:672)

    at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:52)

    at weblogic.application.internal.BaseDeployment.activate(BaseDeployment.java:212)

    at weblogic.application.internal.EarDeployment.activate(EarDeployment.java:59)

    at weblogic.application.internal.DeploymentStateChecker.activate(DeploymentStateChecker.java:161)

    at weblogic.deploy.internal.targetserver.AppContainerInvoker.activate(AppContainerInvoker.java:79)

    at weblogic.deploy.internal.targetserver.BasicDeployment.activate(BasicDeployment.java:184)

    at weblogic.deploy.internal.targetserver.BasicDeployment.activateFromServerLifecycle(BasicDeployment.java:361)

    to weblogic.management.deploy.internal.DeploymentAdapter$ 1.doActivate(DeploymentAdapter.java:52)

    at weblogic.management.deploy.internal.DeploymentAdapter.activate(DeploymentAdapter.java:200)

    to weblogic.management.deploy.internal.AppTransition$ 2.transitionApp(AppTransition.java:31)

    at weblogic.management.deploy.internal.ConfiguredDeployments.transitionApps(ConfiguredDeployments.java:261)

    at weblogic.management.deploy.internal.ConfiguredDeployments.transitionApps(ConfiguredDeployments.java:246)

    at weblogic.management.deploy.internal.ConfiguredDeployments.activate(ConfiguredDeployments.java:170)

    at weblogic.management.deploy.internal.ConfiguredDeployments.deploy(ConfiguredDeployments.java:124)

    at weblogic.management.deploy.internal.DeploymentServerService.resume(DeploymentServerService.java:181)

    at weblogic.management.deploy.internal.DeploymentServerService.start(DeploymentServerService.java:97)

    at weblogic.t3.srvr.SubsystemRequest.run(SubsystemRequest.java:64)

    at weblogic.work.ExecuteThread.execute(ExecuteThread.java:256)

    at weblogic.work.ExecuteThread.run(ExecuteThread.java:221)

    In the workspace, it shows that the Service is pending.

    14.PNG

    EMP Diagnostic Report:

    13.PNG

    Can help kindly out how should I solve this problem.

    I restarted the services and rebooted the Machine but still getting the same error.

    Kind regards

    VJ


    Hello

    I've reconfigured the Reporting, analysis, and everything by, I chose "Drop table" and the issue was resolved.

    Kind regards

    VJ

  • BSOD "driver irql not less or equal" and the "thread of unhandled exception" messages

    Hi all

    Since I got my laptop motherboard replaced I started having BSOD issues with "driver irql not less or equal ' and"unhandled exception thread"messages. They appear very often (about once a week), but it's annoying anyway :) I failed to note any regular pattern in BSOD problem.

    I've read the description of similar problems, so I guess that the problem is a faulty driver. Unfortunately my PC skills are not sufficiently advanced to solve the problem on my own.

    Operating system

    64-bit Windows 8
    CENTRAL PROCESSING UNIT
    Intel Core i5 3210M @ 2.50 GHz 61 ° C
    Ivy Bridge 22nm technology
    RAM
    6,00 GB Dual-Channel DDR3 @ 665 MHz (9-9-9-24)
    Motherboard
    Acer VA50_HC_CR (U3E1)
    Graphics
    Monitor generic PnP (1366x768@60Hz)
    Graphics Intel HD 4000 (Acer incorporated [ALI])
    Storage
    465 GB TOSHIBA MQ01ABD050 (SATA) 39 ° C
    Optical drives
    HL-DT-ST DVDRAM GT70N
    Audio
    Realtek High Definition Audio

    Antivirus: Kaspersky Crystal

    The Minidump files: https://onedrive.live.com/redir?resid=A32073C9ADCE674! 106 & authkey =! AEZQAT-sNxtbU1Y & ithint = the file % 2crar

    Thanks in advance.

    The debugging session: killed Sep 16 01:29:43.916 2014 (UTC - 04:00)
    System Uptime: 0 days 0:30:20.630
    Loading the kernel symbols
    ...............................................................
    ................................................................
    ............................................................
    Loading user symbols
    Loading unloaded module list
    .......

    Use! analyze - v to obtain detailed debugging information.

    BugCheck D1, {b, 0, 0, fffff88005abf4b6}

    Cannot load the image \SystemRoot\system32\DRIVERS\athw8x.sys, 0n2 error Win32
    WARNING: Unable to verify timestamp for athw8x.sys
    ERROR: Module load completed but symbols can be loaded for athw8x.sys
    Probably caused by: athw8x.sys (athw8x + 684b 6 )

    Follow-up: MachineOwner

    Atheros Wireless LAN Driver Update.

    Loaded symbol image file: athw8x.sys
    Image path: \SystemRoot\system32\DRIVERS\athw8x.sys
    Image name: athw8x.sys
    Timestamp: Thu Jul 24 11:44 2012 (500EC2C0)

    First try ACER Support.

    http://us.Acer.com/AC/en/us/content/drivers

    Description of the driver: Atheros Wireless LAN driver

    Driver update site: http://www.Atheros.cz/

  • How String concat and number?

    This is my code:

    PMString strLabel is 'TXT-' + 1;.

    But result = 'TXT '.

    How String concat and number?

    Hi daitranthanhoa,

    PMString has an AppendNumber function.

    Markus

  • How to get the part of string before and after a character

    Hi all

    How to get the string before and after the comma character)

    Ex: The string contains the value John Kennedy

    I need the output as first stirng - John

    Second stirng - Kennedy

    Create table names (fullname varchar2 (20));

    insert into values of names ("John, Kennedy");

    insert into values of names ("papa ibra, Shan");

    insert into values of names ('Don Bosco'),

    Select * from names;

    Expected results

    FullName firstname lastname

    John, Kennedy John Kennedy

    Nicolas, Nicolas Shan Shan

    Don Bosco Don Bosco

    Please let me know how to proceed

    Thank you

    Hello

    This proves what I said before, on 0 and several commas commas.

    If we add these 3 rows to the sample data you posted:

    insert into names (fullname) values ("tou").

    insert into names (fullname) values (' David, Lloyd, George ");

    insert into names (fullname) values ('J, R, R, Tolkien");

    then the query I posted earlier produced these results:

    FULLNAME FIRSTNAME LASTNAME

    -------------------- -------------------- --------------------

    John, Kennedy John Kennedy

    Nicolas, Nicolas Shan Shan

    Don Bosco Don Bosco

    TOU tou

    David Lloyd, George David Lloyd, George

    J, R, R, Tolkien J R, R, Tolkien

    If you prefer to get these results:

    FULLNAME FIRSTNAME LASTNAME

    -------------------- -------------------- --------------------

    John, Kennedy John Kennedy

    Nicolas, Nicolas Shan Shan

    Don Bosco Don Bosco

    TOU tou

    David Lloyd, George David, Lloyd George

    J, R, R, J, R, R Tolkien Tolkien

    then you just change line 1:

    WITH got_commapos AS

    (

    SELECT FullName

    , INSTR (fullname, ','-1) AS commapos-* CHANGED *.

    Names

    )

    SELECT FullName

    , SUBSTR (fullname, commapos 1, -1) AS a first name

    SUBSTR (fullname, commapos + 1) in the FORM name

    OF got_commapos

    ;

  • can any contact pone want me is vmfs and difference between vmfs 5.0 and vmfs3

    can any contact pone want me is vmfs and difference between vmfs 5.0 and vmfs3

    A nice Article may help: comparison between VMFS3 & VMFS5 | Vmwareminds

  • How this difference to check superior or equal and less than another date?

    Hi, I have two dates with 2011-05-11 and 2014-05-24 (yyyy-mm-dd) format I want a calculation based on the comparison.

    I used the date_diff function. But it does not work as expected.

    Thank you and best regards,

    Ramanantsoa

    Hello

    How you implement your logic?

    You do not, you can do it this way, apply less, grater than or equal to operator

    1 If date diff is grater than zero and then perform the action desire

    R: 2014-05-20

    B: 2014-05-23

    0? >

    . . . . .

    Result: Condition would be true that diff is 3

    2 if date diff is less than zero, then perform the action desire

    R: 2014-05-23

    B: 2014-05-20

    0? >

    . . . . .

    Result: Condition would be wrong as diff-3

    3 if date diff is zero, then perform the action desire

    R: 2014-05-23

    B: 2014-05-23

    0? >

    . . . . .

    Result: Condition would be wrong as diff 0

  • String equal?

    I have an instrument that communicate with the PC via RS232. So I use VISA write, read...

    It works OK, but have the following problem

    I want to compare two strings, one is constant other out by VISA read. If I use the indicator, this is the show "hexagonal"(par exemple 3E04 4B73) the value of VISA, but if I use the same wire to the 'equality?' to compare two strings is strange... return values ".

    We see them all together to see what my problem is:

    A string is an array of bytes interpreted as text characters.

    If the string that appears as '3E04 4B 73' mode normal consists of the characters '3' ASCII '0' ' E' '4' '' '4' 'B' '7' '3 '. The hexadecimal values in the ASCII characters are "3345 3034 2034 4237 33.  ASCII 3 = 33 hex.  ASCII E = 45 hexagonal.

    If you want to type in the hexadecimal values to a control of the chain or the constant, you must assign to the hex display.

    To see what is in a thread of string in a string to the conversion of primitive bytes and the wire table then said to a table indicator output.  This will show the numerical values of each byte of the string.  You can set the digital display to decimal, hexadecimal, octal, or binary.

    Lynn

  • Confusion on the tiny model M92p variants and differences

    Hi all

    I make a purchasing decision for M92p tiny (do not know what is the appropriate form for him, is it SFF or USFF or something like Mini ITX).

    I can see on various websites there are different model variants listed for this series, for example on the official lenovo, he mentions around 9 variants of M92 and M92p.

    http://support.Lenovo.com/us/en/documents/pd024438

    So, I'm totally confused as to what is the exact model, I'll buy. If anyone can, then please answer the following queries:

    1. What is the difference between M92 and M92p (known as "tiny")

    2. What is the difference between all the variants of the model numbers on the support Web site. I'm a 3235, he therefore M92 or M92p.

    3 in case to get accurate detailed data sheets for all model with the numbers part numbers so I tried option but it did not. A web link would be really useful.

    Thank you for reading and answering queries.

    Resolved:

    http://download.Lenovo.com/parts/ThinkCentre/M92_M92p%20fru%20List%20Tiny%206-28-2012.PDF

  • How can I set a time string (start and end time) to tiara?

    I wish to address a string of hour to 8 hours. Set the time of the departure of 16/03/2015 17:18:31 to 16/03 / 2015 09:18:31 (mm/dd/yyyy hh: mm :).) Is there an easy way (like the analysis or a script)?

    Either use a script like this

    Option Explicit

    data. Root.Clear
    protected chObj: set chObj = data.root.ChannelGroups.Add ('group'). Channels.Add ("time", DataTypeChnDate)
    chObj.Values (1) = CDate ("16/03/2015 17:18:31")
    Dim chNr: chNr = chObj.Properties ("number"). Value

    protected offsetInSeconds: offsetInSeconds = 8 * 60 * 60
    Call ChnOffset (chNr, chNr, "free offset")

    or use

    Analysis.Basic Mathematics.Offset Corrections

    and add the offset in seconds as "add any compensation."

  • String concatenation and put into registry to offset slowing computer

    Hi all

    I tried to create a record of comms between LabVIEW and an Arduino by concatenating the current message with previous posts and put in a shift register.  After a few hours the LabVIEW began to crawl.

    I had a vague idea that you could write a string indicator without wiping the old content.  I thought that if I could do that is there not a huge overload copy all a larger string.

    Am I dreaming?

    Thank you

    If you need registration integer comm I would say the comms streaming the file.  Make sure you put a Boolean value in to turn off logging.

    Usually, it's one of those things you just do everything in debugging.  If so use OR spy rather than writing your own debugger.

  • Search for the string in the string table and see the following value in the line

    Hi, I'm new I have LV and I do a Vi that read worksheet values and generates 2d channels of the same spreadsheet table. For the moment everything I need is a function that find specyfic string in this table and show the next value in a line. As:

    Table:

    a; b
    c; d
    f; g

    example: find the 'c '.

    VI shoud show "d".

    Concerning

    Not a bad homework problem.  Do it with pencil and paper.  Write your table and pretend you're the computer.  What you want to do (step by step)?  What questions do you have?

    Now that the translation a bit to computers.  You mentioned that the data is in an array of strings.  What structures (LabVIEW) work with tables?  [Do you know how to work with tables?  [Otherwise, review some of LabVIEW Tutorial material - see top right of the first page of the Forum].  What do you know about channels?  What questions you need to ask questions on the channels?  What do you know about string functions?

    Watch these things in some LabVIEW code, 'feed' some data and see what he does.  If it seems to do things "unexplained", you can try to look at the block diagram to run by turning the performance highlight (and if you don't know what that means, use the help of LabVIEW and see the tutorials).

    Bob Schor

Maybe you are looking for

  • Reputation points

    This may seem a stupid question and if so, I apologize, but why our totals have been removed from beneath our avatars?  It is slightly irritating to have to keep control of my profile to see if someone has been kind of marking no response from my hel

  • I can't install the wireless on Satellite L40-14B

    I can't install the wireless on this laptop. Was bought new with no software on it.I tried all the drivers recommended by Toshiba partner site: http://aps2.toshiba-tro.de/wlan/?page=downloadsIntel PRO/Wireless 2100Intel PRO/Wireless 2200/2915Intel PR

  • HP Pavilion Notebook G6: I can spend the ram in my laptop

    Can someone help me with a qeustion on my laptop? Can I add more ram I will list the specifications of it and so can't you list where I can get all this! Motherboard

  • Class LVOOP process data Bug?

    Hello world Not sure if it is a real bug, but I have seen that he sent anywhere.  I created a really basic LV class with members of private data and some data access screws when I renamed one of my data members then name didn't and don't get spread n

  • Journal of trace failed downloads FTP in Lightroom

    Sometimes when I do a ftp transfer, I get a message saying that some of the photos have not been correctly downloaded. If I click on OK, this information went. Is there a kind of diary of download where can I get it back? Thank you.