how to count the exact number of words in a string that has empty spaces between words?

前端 未结 9 1795
猫巷女王i
猫巷女王i 2020-12-03 14:35

Write a method called wordCount that accepts a String as its parameter and returns the number of words in the String. A word is a sequence of one or more nonspace characters

9条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-03 15:35

    http://docs.oracle.com/javase/7/docs/api/java/lang/String.html#split(java.lang.String)

    Splits this string around matches of the given regular expression.

提交回复
热议问题