Forums Register Login

Count the String

+Pie Number of slices to send: Send
I want to find out how many times String 'java' appeared in the particular file. How can i do that?
+Pie Number of slices to send: Send
What have you tried? So far we don' know if you're stuck reading a file, finding the string "java", counting or showing the results.

Some places to look in the JavaDoc: File & FileReader, String.indexOf(), Pattern & Matcher. See if any of those get you going. If you get part way and get stuck, show us some code and we'll help keep you moving.

Take small steps - don't try to write the whole program in one sitting - and have fun!
+Pie Number of slices to send: Send
  • Open the file
  • Read each line
  • If you find "java" increment a counter


  • Which part are you unsure how to do?
    +Pie Number of slices to send: Send
    But Paul wouldn't want you to forget to test with a line that says

    How about punctuation? Only you know your rules here. Maybe lines like:

    How do they get the deer to cross at the signs? Or to read this tiny ad?
    a bit of art, as a gift, that will fit in a stocking
    https://gardener-gift.com


    reply
    reply
    This thread has been viewed 1105 times.
    Similar Threads
    convert an array of String to char
    encoding and decoding in java
    convert String in to String array ???
    Working with RDF
    Class definition
    More...

    All times above are in ranch (not your local) time.
    The current ranch time is
    Mar 28, 2024 06:12:59.