wood burning stoves 2.0*
The moose likes Java in General and the fly likes ASCII value for Empty String. 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 » Java in General
Bookmark "ASCII value for Empty String." Watch "ASCII value for Empty String." New topic
Author

ASCII value for Empty String.

vaibhav kumbhar
Greenhorn

Joined: Mar 22, 2012
Posts: 4
Hi,

I was searching for ascii value of an empty string, ie "". I also wrote a small class for printing the ascii using character array but it gave me nothing. Does an empty string have an ascii value??
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4343
    
    8

No. Characters have ASCII values, not strings. And an empty string has no characters.
Raghavan Muthu
Ranch Hand

Joined: Apr 20, 2006
Posts: 3344

Good suggestion by matthew.

you can refer this website http://ascii-table.com/ for your ASCII values search.

Ideally if you map it to an empty character, you would be placing a space character, which we ideally tend to interpret / mean that as an empty string. In that case, it is decimal 32. You can click on a particular character in the home page of the website where in you can see the relevant details on the right side.

See this sample program.



The output what you get is



Everything has got its own deadline including one's EGO!
[CodeBarn] [Java Concepts-easily] [Corey's articles] [SCJP-SUN] [Servlet Examples] [Java Beginners FAQ] [Sun-Java Tutorials] [Java Coding Guidelines]
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Raghavan Muthu wrote:
Ideally if you map it to an empty character, you would be placing a space character, which we ideally tend to interpret / mean that as an empty string. In that case, it is decimal 32.


Bad advice. There's no such thing as an "empty character", and equating an empty String with any character just muddies the water. An empty String, by definition, has NO characters. There's no reason to say that NO characters is equivalent to SOME PARTICULAR character.
Raghavan Muthu
Ranch Hand

Joined: Apr 20, 2006
Posts: 3344

I agree with you Jeff. It was a mistake. Thanks for pointing out.
vaibhav kumbhar
Greenhorn

Joined: Mar 22, 2012
Posts: 4
Thanks All... so the bottom line is only character has an ascii value and since an empty string has no character it doesn't have any ascii value....
Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 3599
    
  14

No. The bottom line is that Strings have no ASCII value *at all*, empty or not.

It's a bit like saying that a song has a pitch. Songs don't have a pitch. The tones they are composed of have a pitch.
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Stephan van Hulst wrote: The bottom line is that Strings have no ASCII value *at all*, empty or not.

Confusion Friend Stephan.. I think I have to read some books on this...
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Confusion Friend Stephan.. I think I have to read some books on this...


A character has an ASCII value. A String (which may contain zero, one, or more characters) does not.

For example, what do you think would be the ASCII value of the String "Go placidly amidst the noise and waste, and remember what comfort there may be in owning a piece thereof. Avoid quiet and passive persons, unless you are in need of sleep. Rotate your tires"?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60783
    
  65

42?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
Consider Paul's rocket mass heater.
 
subject: ASCII value for Empty String.
 
Similar Threads
Char into Integer
how to print ASCII value of a number ?
String array's weird syntax
String to int
parseInt problem