Programming Tutorials Browser Tutorials Articles Struts Tutorials Hibernate Tutorials

  Tutorial: Exercise - Capitalize Words

Write a method which which returns a string first letter in every word capitalized and every other letter in lowercase.

Tutorial Details:

Write a method which which returns a string first letter in every word capitalized and every other letter in lowercase. Assume the first letter is any letter preceded by a non-alphabetic. This is slightly more difficult than Exercise - Count Words, but uses the same basic algorithm.

Hints
One way to solve this is to go down the string one character at a time. Use a boolean variable to indicate whether you're in a word or not. When the variable indicates that you're in a word, change alphabetics to lowercase (use Character.toLowerCase()). You can test for alphabetic characters with Character.isLetter(). If an alphabetic character is encountered when you're outside a word, it must be the first letter so it should be changed to uppercase with Character.toUpperCase() and switch the state of the boolean variable.


 

Rate Tutorial:
http://www.roseindia.net/java/java-tips/data/strings/q-pr-string-if/capitalize.shtml

Read Tutorial at: Click here to view the tutorial

Rate Tutorial:
Exercise - Capitalize Words

View Tutorial:
Exercise - Capitalize Words

Related Tutorials:

The battle of the container frameworks: which should you use? - JavaWorld - January 1999
The battle of the container frameworks: which should you use? - JavaWorld - January 1999
 
Java Tip 71: Use dynamic messaging in Java - JavaWorld - April 1999
Java Tip 71: Use dynamic messaging in Java - JavaWorld - April 1999
 
Design networked applications in RMI using the Adapter design pattern
Design networked applications in RMI using the Adapter design pattern
 
Speed up listener notification - JavaWorld February 2000
Speed up listener notification - JavaWorld February 2000
 
The Lucene search engine: Powerful, flexible, and free - JavaWorld September 2000
The Lucene search engine: Powerful, flexible, and free - JavaWorld September 2000
 
Matchmaking with regular expressions - JavaWorld July 2001
Matchmaking with regular expressions - JavaWorld July 2001
 
Flex your grid layout
Flex your grid layout
 
Use XML data binding to do your laundry
Use XML data binding to do your laundry
 
Eclipse casts shadows
Eclipse casts shadows
 
roots of constants classes
roots of constants classes
 
Dictionary and Thesaurus API for Java
What is the Dictionary and Thesaurus API for JavaTM? The Dictionary and Thesaurus API for Java is a standard-based class library for accessing a dictionary and thesaurus using Java. It provides programming access to wordbook data from the Java programm
 
Declarative Programming in Java
Declarative Programming in Java What makes EJB components special is the declarative programming model through which we can specify the services such as security, persistence, transaction etc., that the container should provide. An EJB only implements
 
FindBugs, Part 2: Writing custom detectors
FindBugs, Part 2: Writing custom detectors How to write custom detectors to find application-specific problems In the first article in this series, I showed you how to set up and execute FindBugs. Now we'll take a look at FindBugs' most powerful fea
 
NIO Tutorials
NIO Tutorials Introduction In the words of Gregory Pierce, "NIO is one of the most important but least understood APIs that came along for the ride with JDK1.4". Couldn't have put it better myself :). The aim of this series of articles is to help you
 
From Writing Programs to Creating Compilers
From Writing Programs to Creating Compilers In this article we build a simple compiler that augments Java with tasks (independent blocks of code that execute in parallel), thus creating a new language called AJ that well supports the programming of syste
 
Network Programming with JavaTM 2 Platform, Standard Edition 1.4 (J2SETM)
This article provides an overview of the new features and enhancements in the Java 2 Platform, Standard Edition 1.4 (J2SE), and shows you how to use them effectively.
 
Welcome to Free search engine secrets: webmaster's guide to search engine registration!
Welcome to Free search engine secrets: webmaster's guide to search engine registration! Welcome To Webmaster's Guide T his site is dedicated to Web related services. Here you can find tools and suggestions to promote your sites to several search
 
Creating EJB clients using the Eclipse Rich Client Platform
This article shows how to build a sample EJB client using the Eclipse Rich Client Platform (RCP), which has become increasingly popularity due to its extensible nature.
 
one-jar
One-JAR is a simple solution to a vexing problem in Java: how to distribute an application as a single jar-file, when it depends on multiple other jar-files. One-JAR uses a custom classloader to discover library jar files inside the main jar.
 
Urchin RSS Aggregator
Urchin is a Web based, customisable, RSS aggregator and filter. It\'s primary purpose is to allow the generation of new RSS feeds by running queries against the collection of items in the Urchin database.
 
Site navigation
 

 

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2006. All rights reserved.