char c = ' '; boolean isWhitespace = Character.isWhitespace(c); System.out.println(isWhitespace); // Output: true
String sentence = "This is a sentence."; for (int i = 0; i < sentence.length(); i++) { char c = sentence.charAt(i); if (Character.isWhitespace(c)) { System.out.println("Whitespace character found at index " + i); } }In this example, we have a string variable 'sentence' containing a typical sentence. We have implemented a loop that goes through each character of the string and determines if it is a whitespace character using the isWhitespace method of the Character class. If a whitespace character is found, we print out a message indicating its index in the string. The Character.isWhitespace method is part of the java.lang package.