[Java]Standardized strings in Java – Standardize string in java

To normalize the string in Java, we need to remove the extra white space at the top, end and mid-strings.
First we manually delete the spaces at the beginning and end by methods trim().
For example we have:

String str = "    nguyen     van     quan   7826    ";
str = str.trim();

Then

str = "nguyen     van     quan   7826"

Following our work will be cut off the extra white space in between the strings. To do this there are many ways, I outlined here 2 basically:
How to 1:

while (str.indexOf("  ") != -1) str = str.replaceAll("  "," ");

+/ s1.indexOf(s2) : method returns the position of s2 in s1.
+/ s.replaceAll(s1, s2) : method replaces all strings s1 into s2 in s. but just browse string s 1 time. So we need to combine all the while loop to be able to replace all.
How to 2:

str = str.replaceAll("\\s+", " ");

The illustrations

class java_chuanhoaxau
{
	public static void main(String[] sgr)
	{
		String str = "    nguyen     van     quan   7826    ";
		str = str.trim();
		str = str.replaceAll("\\s+"," ");
		System.out.println(str);
	}
}

=== update ===
As we have standardized on the chain by removing whitespace nonsense. Now we will normalize the words that will capitalize the first word and proper nouns like (Hanoi, Vietnam Nguyen Van Quan or, …)
To do this, we first normalized basis as above normal. The next step is capitalized the first letter of each word. I use the split method() to split the string into an array of words. Then use String.valueOf().toUperCase() to capitalize the first letter of each word in the end is connected to the rest of their characters in the substring(1).
So has the array from uppercase, followed by linking the words together and apart 1 spaces.

package vietSource.net;

public class ChuanHoaXau {

	public String chuanHoa(String str) {
		str = str.trim();
		str = str.replaceAll("\\s+", " ");
		return str;
	}

	public String chuanHoaDanhTuRieng(String str) {
		str = chuanHoa(str);
		String temp[] = str.split(" ");
		str = ""; // ? ^-^
		for (int i = 0; i < temp.length; i++) {
			str += String.valueOf(temp[i].charAt(0)).toUpperCase() + temp[i].substring(1);
			if (i < temp.length - 1) // ? ^-^
				str += " ";
		}
		return str;
	}

	public static void main(String[] sgr) {
		String str = "    nguyen     van     quan   7826    ";
		ChuanHoaXau chx = new ChuanHoaXau();
		str = chx.chuanHoaDanhTuRieng(str);
		System.out.println(str);
	}
}