简体   繁体   中英

String equality comparison failure in Java

I'm taking a one string value from an object in a object list.

transitionName = transitionList.get(m).getTransitionName().toString();

And another string value from an object retrieved by a EJB query.

changeItem = changeItemFacade.getChangeItem(changeGroupList.get(1));
char tempNewString[] = changeItem.getNewstring();
newString=new String(tempNewString);

Now this Char[] to String comparison is because the Oracle Table which contains the changeItem have defined the coloumn NewString as a CLOB. And the ejb entity defines type of the variable 'NewString' as a Char[] array . So i have to convert it to a string before doing the comparison.

The problem is that this if statement always returns false and doesn't get executed.

if(transitionName.equalsIgnoreCase(newString)){}

When i try to Log the values (Logger.Debug) , It perfectly show the two (equal) string values in the Server Instance log.

Is there something wrong with the way i convert the char[] array?

I tried changing the type of the entity class variable to String(and of course also the getter and setter methods) but doesn't work either.

Try trim() on strings before comparing. Also, look for character encoding differences. – Singularity

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM