remove One Character Words - Java java.lang

Java examples for java.lang:String Replace

Description

remove One Character Words

Demo Code


//package com.java2s;

public class Main {
    public static String removeOneCharacterWords(String input) {
        String output = "";
        String[] input_text = input.split("\\s+");

        boolean isSW = false;

        for (int i = 0; i < input_text.length; i++) {
            if (input_text[i].length() == 1) {
                isSW = true;//from   w w w  . j  a v a2 s  .  co m
            }

            if (!isSW) {
                output = output + input_text[i] + " ";
            }
            isSW = false;
        }
        if (output.length() > 0) {
            output = output.substring(0, output.length() - 1);
            output = output.toUpperCase();
        }

        return output;
    }
}

Related Tutorials