This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes string variable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "string variable" Watch "string variable" New topic
Author

string variable

kahkean chor
Ranch Hand

Joined: Jan 26, 2013
Posts: 56
can someone tell me what is the deference between

str a = "abc"


str a ="+i+";

what is the double + means?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60794
    
  65

Nothing. It's just a string.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Jj Hill
Ranch Hand

Joined: Jul 25, 2011
Posts: 41

The "+" won't do anything while inside the quotation marks - it's just text, a string literal. The only character that has any effect in the string literal is "\".
kahkean chor
Ranch Hand

Joined: Jan 26, 2013
Posts: 56
erm.....so what is the purpose of adding + for the sql statment?

is "SELECT * FROM Student WHERE StudentID = '" + stuID + "';"; equivalent to "SELECT * FROM Student WHERE StudentID = '" stuID "';";
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 7552
    
  18

kahkean chor wrote:erm.....so what is the purpose of adding + for the sql statment?

Completely different question.

Answer: usually to include the value of a variable; although it's not the best way to do it. Have a look at PreparedStatement.

And BTW: How do you imagine we're supposed to know that your strings are part of an SQL statement?

is "SELECT * FROM Student WHERE StudentID = '" + stuID + "';"; equivalent to "SELECT * FROM Student WHERE StudentID = '" stuID "';";

No; because that 2nd statement won't compile.

Winston

Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
kahkean chor
Ranch Hand

Joined: Jan 26, 2013
Posts: 56
so sad i dont get it....btw thanks for your reply
 
Consider Paul's rocket mass heater.
 
subject: string variable
 
Similar Threads
String
String Question
question regarding strings
About String
I/O code exception