answersLogoWhite

0

public class count {

public static void main(String[] args) {

String string = "1 2 3 4";

char[] array = string.toCharArray();

System.out.println("Number of characters in string: " + string.length());

System.out.println("Number of characters in array: " + array.length);

}

}

Output:

Number of characters in string: 7

Number of characters in array: 7

So yes, spaces are taken as single characters in a string.

User Avatar

Wiki User

16y ago

What else can I help you with?