java - Differnce between addfirst and offerFirst methods in ArrayDeque -


have tried out sample program understand difference between addfirst , offerfirst methods in arraydeque of java 6. seem same, suggestions?

public void interfacedequetest() {         try{         arraydeque<string> ad = new arraydeque<string>();         ad.addfirst("a1");         ad.offerfirst("o1");         ad.addfirst("a2");         ad.offerfirst("02");         ad.addfirst("a3");          system.out.println("in block");          (string number : ad){             system.out.println("number = " + number);         } } 

the difference happens when addition fails, due queue capacity restriction:

  • .addfirst() throws (unchecked) exception,
  • .offerfirst() returns false.

this documented in deque, arraydeque implements.

of note arraydeque has no capacity restrictions, .addfirst() never throw exception (and .offerfirst() return true); unlike, instance, linkedblockingqueue built initial capacity.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -