hi
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

Recommended Answers

I suggest you read the API doc for the String class. It will answer many of your quesions. Go to this site and Find String in the lower left, click on the link and the API doc will be in the main window.

Jump to Post

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.

Jump to Post

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.

Jump to Post

All 9 Replies

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 ?

like
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.

@James
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.

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.

I think the simpler the better for this one.
Later work on the harder stuff.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.