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 When can you use the comma operator 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 "When can you use the comma operator" Watch "When can you use the comma operator" New topic
Author

When can you use the comma operator

tyrone cabero
Greenhorn

Joined: Oct 04, 2003
Posts: 4
sirs,
if u have any idea please help me for my final project
thanks
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

Hi,
The Java language specification makes no mention of a "comma operator;" Java doesn't have one like C does. But I do know what the question means.
You can use a comma to separate variables in a single declaration, like

but that's not considered an instance of the comma operator. You can do the same thing in a for loop:

but that's still not it. The one place in Java where a comma can be used outside of a variable declaration or argument list is in for-loop initialization and increment code, like this:

That's the closest thing to C's comma operator there is in Java. Even so, it's not very close, because the values of any expressions are discarded and not used for anything.


[Jess in Action][AskingGoodQuestions]
John Smith
Ranch Hand

Joined: Oct 08, 2001
Posts: 2937
Comma is one of the separators in Java, and it is used to define the formal grammar of the language. For a complete set of rules, see 18.1 The Grammar of the Java Programming Language. From the rules, you can identify all the cases when comma is used as a separator.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: When can you use the comma operator