Any problem with if(s1==s2 || s1.equals(s2))

When you do not know how the strings are created either as �values of constant expressions� or as �new String objects�, i think most effective way to compare two strings for their equality is by:
if(s1==s2 || s1.equals(s2)){
System.out.println("s1 and s2 are equal");
}else {
System.out.println("s1 == s2 are not equal");
First part of the �if condition� (s1==s2) takes care if they are values of constant expressions, and is faster which is good.
Second part of the �if condition� s1.equals(s2) takes care if either s1 or s2 or both of them are new String objects which a bit slower as they compared char by char.
By the way i know that s1.equals(s2) is good enough to find if their values are or not. But i want to take advantage reference comparison(==) as it is faster than char by char comparison (equals()) method.
And also fact that if conditions are evaluated from left to right and if first one is good it does not do the rest of the contions for or operation.
Any issues with the above code?
Any better ideas?

1. What if s1 is null and s2 isn't?
2. Most equals methods do that == check first. In fact here is the source code for String's equals:
public boolean equals(Object anObject) {
     if (this == anObject) {
         return true;
     if (anObject instanceof String) {
         String anotherString = (String)anObject;
         int n = count;
         if (n == anotherString.count) {
          char v1[] = value;
          char v2[] = anotherString.value;
          int i = offset;
          int j = anotherString.offset;
          while (n-- != 0) {
              if (v1[i++] != v2[j++])
               return false;
          return true;
     return false;
    }3. Don't sweat about these sorts of minor efficiency details.

Similar Messages

  • I am going to buy unlocked iphone 5.. i will be going to india nxt months and will stay there for a while... so my question is will i get warrenty in india.. and will there be any problem with using indian sims..?? thnx for the help..

    i am going to buy unlocked iphone 5.. i will be going to india nxt months and will stay there for a while... so my question is will i get warrenty in india.. and will there be any problem with using indian sims..?? thnx for the help..

    The warranty for the iPhone is not and has never been International.
    Warranty and support are ONLY valid in the country of origin.  The only exception is the EU where the entire EU is treated as one country.
    If the device will be used in India, buy it in India.
    An unlocked iPhone will work on any supported GSM carrier world wide.  The LTE portion of a US purchased, unlocked iPhone is unlikely to work outside North America as it does not support the appropriate bands used in other countries.

  • SOLVED - Has anyone had any problems with xorg 1.11.14-1?

    Last night I had a double catastrophe. The first was nothing to do with Linux, but was the result of a rogue drive trashing my sata ports and killing both Arch and Windows. I managed to rescue Windows, but since Arch was running at the time (and updating) nothing I tried could bring it back. After restoring from a backup (10 days old) I started the updates again (a gargantuan 415Mb) which completed, though after a reboot X failed to start. Nothing in the logs, and no activity at all. My usual fix is to remove xorg.conf and reboot, which will generally get me to the desktop to troubleshooting stage using vesa drivers instead of catalyst, but even this couldn't get me to a desktop. I tried removing catalyst altogether from single user mode, but nothing would fix.
    I restored the backup again, and did all updates except kernel, catalyst, and xorg. Everything worked fine, so next I updated catalyst - still working. A fresh backup and I updated the kernel. Still working, which means the only thing not updated at this point (and in my mind the most likely culprit for the failures) is xorg.
    Now I'm not daft enough to try updating before I make a fresh backup (I've remade several tweaks to my system that got lost after the original crash), but before I go to the trouble, I wondered has anyone else had any problems with the updated xorg?
    For info, I'm running on a Phenom X4 965BE, AMD 4670HD with catalyst 12.1, kernel 3.2.2-1.
    TIA
    Last edited by Roken (2012-02-06 00:30:59)

    Any idea where the problem was?
    X also fails to start for me now, when the catalyst driver is loaded. It used to work before, but after recent upgrades and changes to the system it's somehow broken.
    (Same catalyst and xorg versions as you mentioned, but with kernel 3.2.4-1)
    Switching to the open-source radeon driver makes X start fine, switching back to catalyst breaks it again.
    Last edited by sas (2012-02-07 16:02:50)

  • Any problems with the recalled hard disk drives, any problems with the recalled hard disk drives

    Has anyone had their defective hard drive replaced? 
    any problems with the Apple service or restarting the machine with a new hard drive?

    See this FAQ: http://www.thexlab.com/faqs/freeingspace.html

  • If I change the nation setting of my iTunes in order to buy a song from the American iTunes store, then change my setting back to the Korean store (where you cannot buy music) will that create any problems with my downloaded content?

    If I change the nation setting of my iTunes in order to buy a song from the American iTunes store, then change my setting back to the Korean store (where you cannot buy music) will that create any problems with my downloaded content? I want to buy an album that I cannot get hold of in Korea, but it is available in the US iTunes store. However since most of my apps are downloaded from the Korean store I'll need to switch back in order to update them. Does anyone know if there are any issues in doing this. I'd rather find out before I spend money, change my store setting back to Korea, and then get told I can't listen to the music because I bought it from the US store and my iTunes is set to the Korean store.
    Cheers.

    You canot easily change your country settings.  The iTunes Store in a country is intended only for use by that country's residents, and only while they are in the country. To use the iTunes Store in a country you need a credit card (or other card type if acceptable in a country) issued in that country, billed to an address in that country, and also be physically present in that country when using the store.  You are also restricted to waiting 90 days between country changes.
    E.g., "The iTunes Service is available to you only in the United States, its territories, and possessions. You agree not to use or attempt to use the iTunes Service from outside these locations. Apple may use technologies to verify your compliance." - http://www.apple.com/legal/itunes/us/terms.html#SERVICE

  • Can SAP GRC AC 5.3 connect without any problem with SAP R/3 4.7 Enterprise?

    hello,
    I went to the PAM in the SAP Marketplace to see if SAP GRC AC 5.3 could connect to SAP R/3 4.7 Enterprise but I can't see all the "Add-On Product Version for...", it's cut off.
    Can SAP GRC AC 5.3 connect without any problem with SAP R/3 4.7 Enterprise?
    If I can't is there any proof about it? I have to show it to a client.
    Best Regards,
    Pablo Mortera,

    Pablo,
    GRC AC 5.3 works perfectly fine with SAP's R/3 4.6c, mySAP ERP 4.7 and ECC systems. In fact we have two 4.7 Enterprise systems connected to GRC AC 5.3 system.
    You can get the details of supported SAP ERP systems under prerequisite section of Info page of GRC AC 5.3 , it can be accessed on marketplace at -
    Downloads-->Installations and Upgrades - Entry by Application Group > SAP Solutions for Governance, Risk, and Compliance>SAP GRC Access Control>SAP GRC ACCESS CONTROL>SAP GRC ACCESS CONTROL 5.3
    Just ensure to have proper BASIS and ABAP support pack level as mentioned in prerequisites.
    Regards,
    Amol

  • What,s the reason to stop iphone 5?? Is there any problem with that phone?? Because still 4s is in market but iphone 5 is stopped.... What,s wrong with apple??

    Why apple stoped iphone 5? What's the reason?? Is there any problem with that phone... Because iphone 4s is still in market.. But they stopped iphone 5.. What's wrong with iphone 5????

    It was replaced by the iPhone 5C, which is essentially the same phone except for the case, better LTE converage and a larger battery.

  • When attempting to use Lightroom external editor program to edit a photo in Photoshop Elements 10, the photo does not open / appear on photoshop elements screen.  I don't have any problem with this when using Photoshop Elements 6 or Photoshop CS.  I'm usi

    When attempting to use Lightroom external editor program to edit a photo in Photoshop Elements 10, the photo does not open / appear on photoshop elements screen.  I don't have any problem with this when using Photoshop Elements 6 or Photoshop CS.  I'm using a Mac with Mountain Lion OS.  Any solutions?

    Adobe now hides the editor - what looks like it is not - you want the editor hidden in the support folder - see http://forums.adobe.com/message/3955558#3955558 for details
    LN

  • On my Mac Mini, I keep getting this error message: "iCloud encountered an error while trying to connect to the server".  I don't have any problems with iCloud on my laptop / PC.  It works fine... Does anyone know what the problem could be?

    On my Mac Mini, I keep getting this error message: "iCloud encountered an error while trying to connect to the server".  I don't have any problems with iCloud on my laptop / PC.  It works fine... Does anyone know what the problem could be?

    Your Mac must be on Lion (10.7) to run iCloud. Apple had to change the operating system to fully support it. Nevertheless, it is possible to get emails from iCloud without having Lion. Please tell me if this interests you.
    Anyways, here is the link to buy Lion (30 dollars, totally worth the upgrade ): http://itunes.apple.com/be/app/os-x-lion/id444303913?mt=12
    Franklin

  • I have a Mac OS X 10.6.8 and wish to upgrade to newest version...any problems with that?

    i have a Mac OS X 10.6.8 and wish to upgrade to newest version (yosemite?)...any problems with that?

    Read the system requirements for Yosemite.

  • Workstation specs -- Any problems with this system quote?

    Here are the specs I have been quoted.  I'm not terribly knowledgeable about hardware, does anyone see any problems with this system?  I have recently started shooting and editing weddings, engagements and corporate videos.  I think it may be bit more than I need, but I would much prefer that to less than I need.  Any input from the more tech savvy users would be much appreciated.
    Darren Breckles
    65539
    ASUS Sabertooth X79 ATX LGA2011 DDR3 3PCI-E16 2PCI-E SATA3 USB3.0 SLI CrossFireX Audio Motherboard [Sabertooth X79]
    72374
    Mushkin Enhanced Blackline Frostbyte 32GB 4X8GB PC3-12800 DDR3-1600 CL10 Quad Channel Memory Kit [994055]
    64540
    Noctua NH-D14 SE2011 LGA2011 Heatpipe Cooler w/ NF-P14 140mm & NF-P12 120mm PWM Fans [NH-D14 SE2011] [Reg. $89.99]
    67678
    Intel 520 Series 240GB 2.5in SSD MLC 25nm SATA3 Solid State Disk Flash Drive OEM [SSDSC2CW240A310] [Reg. $279.99]
    4729477
    8 port internal via 2X SFF-8087, LSI2208 1GB cache, 6Gb/s, RAID 0/1/10/5/50/6/60 [RS25DB080]
    1
    84358
    MSI GeForce GTX 770 OC Twin Frozr IV 1098/1150MHZ 2GB 7GHZ GDDR5 2xDVI HDMI DP PCI-E 3.0 Video Card [N770 TF 2GD5/OC] [Reg. $429.99]
    62678
    ASUS BW-12B1ST Blu-Ray Writer 12X BD-R 16X DVD+R SATA Black Retail [BW-12B1ST/BLK/G/AS][Reg. $89.98]
    Environmental Fee $0.75 Per Item
    45275
    Microsoft Windows 7 Professional Edition 64Bit DVD SP1 OEM [FQC-04649] [Reg. $153.98]
    75044
    Fractal Design Define R4 ATX Tower Case Black Pearl 2X5.25 8X3.5INT No PSU Front 2XUSB3.0 Audio [FD-CA-DEF-R4-BL] [Reg. $119.99]
    77641
    Corsair AX860 860W ATX 12V V2.31 80 Plus Platinum Modular Power Supply Active PFC 120mm Fa *IR-$10* [CP-9020044-NA] [Reg. $189.89]
    49665
    nMedia ZE-C118 3.5in Multi Function Panel Flash Card Reader W/USB2.0 eSATA SDHC2.0 Win 7 Black [ZE-C118 ] [Reg. $19.99]
    58276
    StarTech.com 3.5in Hard Drive to 5.25in Front Bay Bracket Adapter [BRACKETFDBK]
    78186
    Noctua NF-A14 FLX 140mm Ultra Quiet Cooling Fan 900-1200RPM 115.5M3/H 19.2DBA 3-PIN [NF-A14 FLX] [Reg. $22.99]
    4
    22823
    Premium PC Assembly and Testing With 1 Year Limited NCIX Warranty (PRE-CONFIG WIN. OS If Purchased)
    Environmental Fee $3.00 Per Item
    Note: Includes extra attention to cabling, lighting installation and extra burn-in period. Recommended for windowed cases. Assembly requires an additional 4-5* business days to ship once all parts are in stock. *typical lead time (currently 2-5 business days)
    1
    $3.00
         73920-1
    NCIX 3 Year On-Site Care Coverage for PC $3000.00 - $3999.99 (22823)
    89510
    Intel Core i7 4930K 6 Core 3.4GHZ (3.9GHZ Turbo) 12MB Hyperthreading LGA2011 Processor No HSF [BX80633i74930K] [Reg. $649.99]
    81958
    Western Digital RE 2TB SATA3 7200RPM 64MB Cache 3.5in Internal Hard Drive [WD2000FYYZ] [Reg. $213.57]
    Environmental Fee $0.75 Per Item
    4

    Very nice build list Darren!
    I would have selected the Samsung 840 Pro 256GB SSD over the Intel 520, and Areca's ARC-1882i over the Intel SAS controller you list, but those are preferences not essential changes.
    Regards,
    Jim

  • I'm using mac with the newest operating system (snow leopard 10.6.7). since I've updated to Firefox 4 It doesn't display Hebrew fonts- I didn't have any problems with it before the upgrade and in safari I don't have this problem.

    Hello, I'm using Mac with the newest operating system (snow leopard 10.6.7). since I've updated to Firefox 4 It doesn't display Hebrew fonts… I didn't have any problems with it before the upgrade and in safari I have no problem with it. please help me- I don't like to use safari a my browser...

    elly903 wrote:
    Before commenting - I CANNOT install Mavericks because it'll mess up the versions of Filemaker Pro and Quicken that I use regularly...
    Quicken 2007 for Intel (Snow Leopard, Lion, Mt. Lion and Mavericks) for $15:
    http://quicken.intuit.com/personal-finance-software/quicken-2007-osx-lion.jsp
    It will input your Quicken PPC data file directly if it was Quicken 2005 through 2007.  If older you need Quicken 2006 or 2007 PPC first to convert your data file; and this update must be done BEFORE you upgrade to Mavericks:
    http://quicken.intuit.com/support/help/patching/quicken-2006-manual-updates--mac -/GEN82200.html
    Filemaker Pro PPC (in this case 7) running in Snow Leopard Server installed into Parallels for use in Lion, Mt. Lion and Mavericks:
                                  [click on image to enlarge]
    Snow Leopard Server: 1.800.MYAPPLE (1.800.692.7753) - Apple Part Number: MC588Z/A (telephone orders only)
    This solution allows you to run your Photoshop Elements in Mavericks concurrently with Filemaker Pro PPC.  Mavericks is a free download.

  • Any problem with AMD Radeon or FirePro graphic cards?

    Hi.
    I know that Adobe recommend Nvidia cards for SpeedGrade, but I ask to owners of AMD cards if they have found any problems with AMD cards: bad performance, not realtime with relatively few layers, etc, etc
    Which is your experience?
    Thanks.

    FWIW: I'm using a AMD Radeon HD 6750M (1GB RAM) on my Mac Book Pro. So far it performs fine, in some cases it even feels faster than the Quadro 4000 in my Mac Pro, but I think that has more to do with the type of projects. Mostly doing DSLR on the MBP and R3D on the Mac Pro.

  • I've never had any problems with iTunes,

    I've never had any problems with iTunes, and one day, without doing anything to it, I tried to open it and it said "iTunes cannot run because some of its required files are missing. Please reinstall iTunes." I've reinstalled it countless times and it still keeps giving me that message. I don't know what to do.

    Hey grossa2,
    First, here is a way to report an issue with your purchase:
    How to report an issue with your iTunes Store, App Store, Mac App Store, or iBooks Store purchase
    http://support.apple.com/kb/HT1933
    Then, I'd go through this article, which helps troubleshoot a lack of audio playback in iTunes:
    iTunes and QuickTime for Windows: Audio does not play or plays incorrectly
    http://support.apple.com/kb/TS1362
    Take care,
    Delgadoh

  • I have F.F 3.6 and windows 7.: 1) When i want to buy a airplane ticket and want to select 2 adults or 2 children, the draw down select, does not work in any websides,? WHY?. 2) Have FF any problems with SKYPE

    I have F.F 3.6 and windows 7.: 1) When i want to buy a airplane ticket and want to select 2 adults or 2 children, the draw down select, does not work in any websides,? WHY?. 2) Have FF any problems with SKYPE
    == This happened ==
    Not sure how often
    == After innstalling windows 7

    As a suggestion I'd put the Text_io segments into their own begin - exception - end sub-blocks within the main code. This way if Text_io does raise an exception you can catch it earlier as it may be able to recover - That is if it is a text_io exception.
    Other than that you;ll have to step through in Debug.

Maybe you are looking for

  • Print Current Date on iCal Printed Output

    My wife likes to print out her weekly calendar from iCal (which she sync's with her iPhone). It would be very useful if iCal could place "the dated printed" on the output hard copy. This would prevent outdated versions of the calendar from getting co

  • Soft references

    1) The only difference that I know between soft references and weak references is that weak references are guaranteed to be garbage collected, however soft references would be garbage collected only if JVM is running out of memory. Now my question is

  • Adding F4 help to a field in a table maintenance dialog

    I have used SE54 to create a maintenance dialog for my table. I need to be able to use F4 in a field in the maintenance dialog that will read several values that have been entered into the table (in the same row) but not yet saved and then execute an

  • Communication between Netweaver and R/3 System

    Hi, I'm trying out the Netweaver sneak preview for testing the capabilities of the pdk for .net. I've added the development R/3 system (4.6C) of our company to the system landscape of the portal. Does the communication between those two systems requi

  • Bw logical system

    hi everybody can anybody explain actually what is this Bw logical system and what is the real need and use for this BWLOGSYS. and how to create by step by step procedure plz. thank you very much in advance thanksand regards neelkamal