Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: recurring counter inside a method

  1. #1
    Junior Member
    Join Date
    Jan 2012
    Posts
    25
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Default recurring counter inside a method

    I'm looking for a way to get a method to keep track of how many times it's been called. Hopefully this is the right forum.


  2. #2
    Super Moderator pbrockway2's Avatar
    Join Date
    Jan 2012
    Posts
    987
    Thanks
    6
    Thanked 206 Times in 182 Posts

    Default Re: recurring counter inside a method

    You could use an instance variable:

    private int fooCalled;
     
    public void foo() {
        fooCalled++;
        // more stuff here
    }

  3. The Following User Says Thank You to pbrockway2 For This Useful Post:

    Goldfinch (February 4th, 2012)

Similar Threads

  1. [SOLVED] method inside main()
    By rohan22 in forum Java Theory & Questions
    Replies: 2
    Last Post: July 14th, 2011, 11:42 PM
  2. [SOLVED] How to get the return of a method inside an object in an ArrayList?
    By Hallowed in forum Java Theory & Questions
    Replies: 7
    Last Post: May 1st, 2011, 10:44 PM
  3. Help With Counter
    By Catgroove in forum Java Theory & Questions
    Replies: 7
    Last Post: February 10th, 2011, 08:50 AM
  4. [SOLVED] Why can't I write to file inside a doGet() method?
    By FailMouse in forum Java Servlet
    Replies: 1
    Last Post: July 7th, 2010, 01:15 AM
  5. Odd Even Zero Counter?
    By velop in forum Java Theory & Questions
    Replies: 1
    Last Post: February 19th, 2010, 02:13 PM