Results 1 to 14 of 14

Thread: a doubt

  1. #1
    Thia is offline Member
    Join Date
    Nov 2009
    Posts
    4
    Rep Power
    0

    Default a doubt

    hi,
    I would like to find number of occurences of objects in each column of a text file.. Can someone tell me how I could do tat?

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    Can you bit more specific? What objects are you looking in a text file, the word object confusing. And also what you've tried so far?

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Hello Eranga! :)

  5. #5
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

  6. #6
    Thia is offline Member
    Join Date
    Nov 2009
    Posts
    4
    Rep Power
    0

    Default

    contents in my text file are like this:
    climate temperature humidity
    /*The above three are the column names*/
    hot high mild
    hot mild cold
    cool mild low..

    the list goes on like this.. I wish to find number of occurences of hot,cool in the the column climate..similarly i wish to find the number of occurences of high,mild in the column temerature..

  7. #7
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

  8. #8
    Thia is offline Member
    Join Date
    Nov 2009
    Posts
    4
    Rep Power
    0

    Default

    ya.. i can do that.. but how to find occurences in each column?

  9. #9
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    If you can read the line of text, then tokernize by using the space character and keep them in an array. Them you can compare with what you want to do the process.

    But this method not more efficient, because you have to deal with the counters are well. Collections in java like List, Map do the job in much better way in such instance.

  10. #10
    Thia is offline Member
    Join Date
    Nov 2009
    Posts
    4
    Rep Power
    0

    Default

    can you send me a sample code for that?

  11. #11
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Why not try to solve it first on your own, then if you run into a problem, post your attempted solution and we can help you work on it.

  12. #12
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by Fubarable View Post
    Why not try to solve it first on your own, then if you run into a problem, post your attempted solution and we can help you work on it.

    I agreed with Fubarable. I gave you the guidance, first give a try on it. If you stuck on something you can ask questions any time. But you must put some effort first.

  13. #13
    MuslimCoder is offline Senior Member
    Join Date
    Jan 2009
    Posts
    119
    Rep Power
    0

    Default

    you could also try counting as u read, like anytime you read you check then increment the appropriate counter. it would make your program a bit faster.

  14. #14
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    You've lots of ways to gain performance in the code, but the most important thing is that the basic model of the application.

    If you've tried something and looking any feedback, post your code here.

Similar Threads

  1. Doubt
    By karthikeyan_raju in forum Advanced Java
    Replies: 11
    Last Post: 11-05-2009, 05:48 PM
  2. have doubt
    By ras_pari in forum Advanced Java
    Replies: 3
    Last Post: 10-01-2009, 10:51 AM
  3. doubt
    By Chris555 in forum Networking
    Replies: 0
    Last Post: 08-05-2009, 03:58 PM
  4. Doubt
    By winkodes in forum Enterprise JavaBeans (EJB)
    Replies: 2
    Last Post: 12-20-2008, 09:34 PM
  5. doubt
    By shaju_inspira in forum Sun Java Wireless Toolkit
    Replies: 0
    Last Post: 01-18-2008, 09:38 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •