Page 2 of 2 FirstFirst 12
Results 21 to 26 of 26
  1. #21
    colpwd is offline Member
    Join Date
    Aug 2010
    Posts
    25
    Rep Power
    0

    Default

    Would you expect it to have holes where items have been removed?
    Yeah i suppose i would. I thought id originally have to keep track of the next element to be removed through the use of my own variable with these holes being existent, but if the ArrayList is acting this way where it shifts and "fills the hole", then thats even better.

  2. #22
    colpwd is offline Member
    Join Date
    Aug 2010
    Posts
    25
    Rep Power
    0

    Default

    Ok, this has led me to ask another question.

    If i declare an ArrayList with no initial capacity,

    ArrayList<String> theory = new ArrayList<String>();

    And i proceed to add a string object into the 5th element (for example). Will this produce an error?
    If yes, is there a way to get around it?

    Update:

    Ok, so as i suspected, it produces an index out of bounds exception.
    Last edited by colpwd; 08-25-2010 at 02:26 AM.

  3. #23
    colpwd is offline Member
    Join Date
    Aug 2010
    Posts
    25
    Rep Power
    0

    Default

    Sorry to keep this thread alive but i was hoping someone may be able to answer a question for me.

    Lets say i have the following,

    Java Code:
    public int temp = 3;
    ....
    class timer1 extends TimerTask
    {
         public void run()
         { 
              System.out.println(temp);
         }
    }
    - I create 3 instances of the Timer and TimerTask object within 10 seconds.
    - Each of these 3 times, the temp variable is altered. (from 3 to 4 to 5)
    - Each Timer is set to fire an event after 20 seconds.

    Will the first timer object to expire print "5" or "3"?

  4. #24
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,792
    Rep Power
    25

    Default

    Will the first timer object to expire print "5" or "3"?
    It seems a waste of time to ask a question when you can write a program and have the computer answer the question.
    Have you tried writing the code and executing it?
    Please do that and let us know what happened.

  5. #25
    mretondo is offline Member
    Join Date
    Dec 2013
    Posts
    1
    Rep Power
    0

    Default Re: Countdown Timer that does not disrupt normal operation

    Quote Originally Posted by colpwd View Post
    Ok, so it appears that the ArrayList is "auto trimming" when i delete an element, so the element i want to remove is always in position 0.

    I'd like to thank everyone for your help.

    colpwd
    Why don't you use a map of indexes to Timers or map of indexes to TimerTasks? Much easier then keeping two arraylists and you don't have to worry about auto trimming.

  6. #26
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,728
    Blog Entries
    7
    Rep Power
    21

    Default Re: Countdown Timer that does not disrupt normal operation

    Don't resurrect long dead threads; I'm closing this one.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Page 2 of 2 FirstFirst 12

Similar Threads

  1. Is it normal to have these feelings?
    By Meta in forum New To Java
    Replies: 15
    Last Post: 05-03-2010, 10:20 AM
  2. how to countdown on server side
    By BigBear in forum Java Servlet
    Replies: 3
    Last Post: 04-26-2010, 11:33 PM
  3. countdown timer, little help with method
    By sidy in forum New To Java
    Replies: 22
    Last Post: 07-19-2008, 01:42 PM
  4. Replies: 0
    Last Post: 04-04-2008, 03:46 PM
  5. CountDown timer
    By Seema Sharma in forum AWT / Swing
    Replies: 1
    Last Post: 03-06-2008, 05:26 PM

Posting Permissions

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