how are you gays
in java i have question about constructors , i just starting learning java since few weeks
how i can define string in construtor using one argument ..

how many constructors are there in the string class >?

how i can count the number of words in a string .

thanx aloot

5 Years
Discussion Span
Last Post by NormR1

yah i read some of methods that help me to understand string class ,,

i want to know how many constructors in string class with explaination or name of those constructors


how many constructors in string class

That is shown in the API doc.
If you have questions about any of what is shown in the API doc, copy it here and ask your questions.


which method can i used to count number of word in string ?

ambitious girl sign in daniweb


There are several steps needed to count the number of words.
You must find the first occurrence of the word and then you must advance past its location to find the next and do the same again to find the next and continue until you do not find any more.

Look at the methods in the String class to see which will look for a String/word and return its location in the String being searched.


There's also a method to split a String into an array of words. That could be useful - it's trivial to find the size of an array.


Not sure the OP is ready for regular expressions.
Words can have ending .,; and be in '"()s

Maybe I misread the requirement. I was thinking: how many times does the word "the" occur in a String.
If I missed the requirement then your solution would be the one to use.

Edited by NormR1: n/a


Regex - maybe not - although this is the archetypal example for that method, so the necessary code is very easy to find.
I jumped to thinking the requirement was "words" as in "white-space delimited strings", but I have to agree that it can be read with a more english-language understanding of "word". An example of typical input and correct output would be useful.

This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.