Java's character and assorted string classes support text-processing
Explore Character, String, StringBuffer, and StringTokenizer
By Jeff Friesen, JavaWorld.com, 10/04/02
- Digg
- Reddit
- SlashDot
- Stumble
- del.icio.us
- Technorati
- dzone
Page 3 of 10
for (int i = 0; i < 16; i++)
System.out.println (Character.forDigit (i, 16));
That fragment converts integer numbers 0 through 15 to their character equivalents in the hexadecimal number system and outputs
those character equivalents (0 through f).
To complement the forDigit(int digit, int radix) method, Character provides the public static int digit(char c, int radix) method, which converts the c-specified character value in the radix-specified number system, to the value's integer equivalent and returns the result. If c contains a nondigit character for the specified number system or radix is not in the MIN_RADIX/MAX_RADIX range, digit(char c, int radix) returns -1. The following code demonstrates that method:
- Digg
- Reddit
- SlashDot
- Stumble
- del.icio.us
- Technorati
- dzone
Resources
- Download this article's source code and resource files
http://www.javaworld.com/javaworld/jw-10-2002/java101/jw-1004-java101.zip
- For a glossary specific to this article, homework, and more, see the Java 101 study guide that accompanies this article
http://www.javaworld.com/javaworld/jw-10-2002/jw-1004-java101guide.html
- Sun's The Java Tutorial, Mary Campione, Kathy Walrath, Alison Huml (Addison-Wesley, 2000; ISBN0201703939) provides a lesson on characters and strings
http://java.sun.com/docs/books/tutorial/java/data/strings.html
- Read Jeff's previous Java 101 column"Packages Organize Classes and Interfaces" (JavaWorld, September 2002)
http://www.javaworld.com/javaworld/jw-09-2002/jw-0906-java101.html
- Go on to Jeff's next column"Tools of the Trade, Part 1" (JavaWorld, November 2001)
http://www.javaworld.com/javaworld/jw-11-2002/jw-1101-java101.html
- Check out past Java 101 articles
http://www.javaworld.com/javaworld/topicalindex/jw-ti-java101.html
- Chuck McMannis discusses the StringTokenizer class in "Lexical Analysis and JavaPart 1" (JavaWorld, January 1997)
http://www.javaworld.com/javaworld/jw-01-1997/jw-01-indepth.html
- Browse the Core Java section of JavaWorld's Topical Index
http://www.javaworld.com/channel_content/jw-core-index.shtml
- Need some Java help? Visit our Java Beginner discussion
http://forums.idg.net/webx?50@@.ee6b804
- Java experts answer your toughest Java questions in JavaWorld's Java Q&A column
http://www.javaworld.com/javaworld/javaqa/javaqa-index.html
- For Tips 'N Tricks, see
http://www.javaworld.com/javaworld/javatips/jw-javatips.index.html
- Sign up for JavaWorld's free weekly email newsletters
http://www.javaworld.com/subscribe
- You'll find a wealth of IT-related articles from our sister publications at IDG.net
good luck with that.By Anonymous on May 11, 2009, 11:47 amgood luck with that.
Reply | Read entire comment
Comparing Characters to a stringBy Anonymous on April 1, 2009, 4:17 amI hve an assignment that requires me to compare 5 characters to a string
Reply | Read entire comment
View all comments