Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

public class Main {
    public static String normalize(String s) {
        if (noString(s))
            return null;
        StringBuilder b = new StringBuilder();
        boolean isWhitespace = false;
        for (int i = 0; i < s.length(); i++) {
            char c = s.charAt(i);
            if (!Character.isWhitespace(c)) {
                b.append(Character.toLowerCase(c));
                isWhitespace = false;
            } else if (!isWhitespace) {
                b.append(' ');
                isWhitespace = true;
            }
        }
        return b.toString().trim();
    }

    public static boolean noString(String v) {
        return v == null || v.equals("");
    }

    public static boolean isWhitespace(String s) {
        boolean ok = true;
        for (int i = 0; i < s.length(); i++)
            ok = ok && Character.isWhitespace(s.charAt(i));
        return ok;

    }
}