Programming Tutorials Browser Tutorials Articles Struts Tutorials Hibernate Tutorials

  Tutorial: Example: String reverse

The following program reverses a string in a very straightforward, but rather inefficient way.

Tutorial Details:

The following program reverses a string in a very straightforward, but rather inefficient way. When you learn about StringBuilder (or the equivalent StringBuffer), you can do this more efficiently. But the purpose of this is to see how looping over a string works.

Nested loops. There are two nested loops in the is program, the outer while loop reads more input. The inner for loop gets every character from the input string starting at character 0.

Counting. A for loop is preferred to a while loop when counting through a series of numbers -- in this case all character positions in a string.

Equivalent. A for loop has the same condition as the equivalent while loop, but also incorporates an initialization, which would be before the while statement, and the increment, which would be at the end of the while body. You can write the loop either way, but putting the initialization, condition, and increment in one statement increases the readability.


 

Rate Tutorial:
http://www.roseindia.net/java/java-tips/flow/loops/ex-string-reverse.shtml

Read Tutorial at: Click here to view the tutorial

Rate Tutorial:
Example: String reverse

View Tutorial:
Example: String reverse

Related Tutorials:

Java decompilers compared - JavaWorld - July 1997
Java decompilers compared - JavaWorld - July 1997
 
Designing with exceptions - JavaWorld - July 1998
Designing with exceptions - JavaWorld - July 1998
 
Script JavaBeans with the Bean Scripting Framework - JavaWorld March 2000
Script JavaBeans with the Bean Scripting Framework - JavaWorld March 2000
 
Use Microsoft's Internet Information Server as a Java servlet engine - JavaWorld June 2000
Use Microsoft's Internet Information Server as a Java servlet engine - JavaWorld June 2000
 
JDBC drivers in the wild - JavaWorld July 2000
JDBC drivers in the wild - JavaWorld July 2000
 
The Gnutella file-sharing network and Java - JavaWorld October 2000
The Gnutella file-sharing network and Java - JavaWorld October 2000
 
Printing in Java, Part 1 - JavaWorld October 2000
Printing in Java, Part 1 - JavaWorld October 2000
 
Access the world's biggest database with Web DataBase Connectivity - JavaWorld March 2001
Access the world's biggest database with Web DataBase Connectivity - JavaWorld March 2001
 
Add ghosted drag images to your JTrees - JavaWorld Tips
Add ghosted drag images to your JTrees - JavaWorld Tips
 
Explore the Dynamic Proxy API
Explore the Dynamic Proxy API
 
Generate JavaBean classes dynamically with XSLT
Generate JavaBean classes dynamically with XSLT
 
A recipe for cookie management
A recipe for cookie management
 
Jini's relevance emerges, Part 1
Jini's relevance emerges, Part 1
 
Best tools for mobile application development
Best tools for mobile application development
 
Sort it out
Sort it out
 
Cracking Java byte-code encryption
Cracking Java byte-code encryption
 
Impressive !
Impressive !
 
What is Web Hosting
What is Web Hosting What is Web Hosting? What is Web Hosting? If you have a company and want web presence than you need a website. With the website any one from the world must be able to view your pages, images etc. Website is actually a
 
SDE for Eclipse
[[http://www.visual-paradigm.com/sdeec.php][The SDE 2.0 for Eclipse (SDE-EC)]] is a powerful, yet the most easy-to-use UML Modelling plugin for Eclipse.
 
DB Visual Architect for Eclipse
DB Visual Architect for Eclipse (DBVA-EC) is a full featured Object Relational Mapping (ORM) plugin for Eclipse that provides the industry\'s best round-trip code engineering support with Java.
 
Site navigation
 

 

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

Copyright © 2006. All rights reserved.