more complete explanation:
"String" will refer to a String constant on the String constant pool.
" String " refers to another String constant on the String constant pool.
" String ".trim() refers to a String instance on the heap.
The left and right operand of your comparison then are two different String instances. The == operator compares whether two object instances refer to the same instance, not whether they have a content identity (iow, whether two object instances are identical on a field comparison).
the equals() member method (as indicated in the previous answer) does that.
== will work for low Number instances referring to Integers and Longs because it has been specifically overridden for that purpose, but that's an exception to a very strict rule.
Hey, so I wanna ask how I need to create a method who will remove word if in that word is 2 same chars. Example: "Potato" in this word there is a 2 "o" chars so this word will need to be removed. "Forum" in this word there is no ...
Help! I want to create a java program that finds the highest even integer among the values entered by the user. Stop asking values when a value less than 1 have been entered. If no even integer is entered, display "No Even Integer"
I am writing a java program that needs to execute shell commands, so I wrote a function that would take the command to execute as a string (ie: "mkdir ~/Folder1") and execute that command with the shell. Here is the function:
Runtime run = Runtime.getRuntime();
Process pr = ...