简体   繁体   中英

Converting Timer[] into list type

I need to convert Timer into list type and shuffle the array and it not possible to start the timer.

protected void stopTimer() throws IOException{ 
       new java.util.Timer().schedule(

    new java.util.TimerTask() {

     Timer tim[] = new Timer[5];
  // LinkedList list = new LinkedList();`
           private java.util.List<Timer> assetList;

           @Override
           public void run() { 
        tim[0] = new Timer(1500,animate);
        tim[1] = new Timer(1500,animate1);
        tim[2] = new Timer(1500,animate2);
        tim[3] = new Timer(1500,animate3);
        tim[4] = new Timer(1500,animate4);
         assetList = Arrays.asList(tim);       
        Collections.shuffle(assetList); 
        assetList.start();  
       System.out.print("iiiiii   === "+assetList);        
          }
  }, 
    5000 
);
  }   

Here, assetList.start(); is not working.

You do have a list of Timer s. However, you are trying to call the method start() on this list. java.util.List does not have this method.

You need to, in one way or another, pick the Timer to start from the list, for example:

assetList.get(0).start();

The above would start the first timer in the shuffled list.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM