Cleaning Punctuation And White Spaces From A String


* Created on Apr 12, 2007
* @author Kushal Paudyal

* This utility class has method to remove punctuation 
* marks from a given string

public class StringCleaner {
 private static String legalCharacterSet;	

 * Default Constructor
 * Create a string that contains standard legal characters.
 * This string will be used to reference whether the 
*  characters in any 'to be cleaned'
 * string are to be kept or not.

 public StringCleaner()

 * We may provide our own set of valid characters which 
 * are to be used on testing the validity.
 * This set is provided as a string containing 
 * valid characters.Order is not important.
 * @param validCharacterSet

 public StringCleaner(String validCharacterSet )

 * @param str The string to be cleaned 
 * (unnecessary characters and whitespaces removed)
 * @return Cleaned String

 public String cleanString(String str)
 	String cleanedString="";
 	for(int index=0;index

 		char currentCharacter=str.charAt(index);

 	return cleanedString;

[My Video Promotion]
  1. How to extract plain Text from HTML Website easily in Java
  2. Find the first non-repeated character in an input String – Java Implementation
  3. Find if a String is rotation of another String – Java Implementation
  4. How To Find What Java Version You Are Using?
  5. Computing the total, free and usable disk space easily using JDK 1.6
  6. Creating and java.util.sql objects from Calendar object
  7. Bar Code Generation In Java Using iText API
  8. Simple Tag Generator In Java For Music Blogs
  9. Tutorial on Converting an List of Strings or Numbers to a CSV file with optional sorting
  10. Calling URL Browser From Java Application
  11. Java Reflection Tutorial – List Methods Of A Class
  12. Cleaning Punctuation And White Spaces From A String
  13. Java Tutorial – Using JCIFS to copy files to shared network drive using username and password
  14. Prime Number Finder In Java
  15. Utility Class For Getting SQL Connection and Closing It
  16. Java Design Pattern – Singleton Pattern
  17. Reading / Writing File in Java and String Manipulation
  18. How to capture a screenshot using Java and save it to a file?
  19. Calculating The Difference Between Two Dates In Terms of Months
  20. Getting The Name Of Currently Logged In User In The System
  21. How To Set And Get System Clipboard Contents In Java
  22. RGB To Hex and Hex To RGB Conversion Using Java and Regular Expressions
  23. Generating Nepali Unicode Sequence For Characters
  24. Java Tool To Compare Two Lists and Spit Out The Differences – Working Example
  25. Replacing non-ASCII characters using Java Regular Expressions
  26. Calculating Folder Size In Java
Tagged , , , , , , , , . Bookmark the permalink.

3 Responses to Calculating Folder Size In Java

  1. Pingback: » Latest Updates

  2. Jamie says:

    This approach uses less memory:

    public static class SizeCounter implements FileFilter
    private long total = 0;
    public SizeCounter(){};
    public boolean accept(File pathname) {
    if ( pathname.isFile()) {
    } else {
    return false;
    public long getTotal()
    return total;

    private static long getFileOrDirectorySize(File file) {
    SizeCounter counter = new SizeCounter();
    return counter.getTotal();

  3. kushalzone says:

    Thank you Jamie for your optimized solution.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.