Delete every nth element from list Java ArrayList vs LinkedList So I wanted to test ArrayList vs LinkedList remove() method times just for fun.  I wrote code below to do it - everything is pretty self-explanatory: deleteEachNth runs through my list and deletes every nth element it sees.  I was expecting to see LinkedList winning by a huge margin, as its remove times are constant-time operations, but my code produces opposite results: for 10000 elements ArrayList is twice as fast.  Naturally, I thought I'd written something wrong, perhaps used a get(), which would slow LinkedList down somewhere, but it isn't the case.  Whats wrong  here?  EDIT: When replacing System.currentTimeInMillis() with System.nanoTime() LinkedList still performs worse for my code.   import java.util.ArrayList; import java.util.LinkedList; import java.util.List; import java.util.stream.IntStream;  public class Test{     List&lt;String&gt; myList;     Test(List&lt;String&gt; someList){         myList = someList;     }     void eliminateEachNth(int n){         for (int i = 1; i &lt; myList.size(); i++) {             if(i%(n-1)==0){                 myList.remove(i);             }         }     }     public static void main(String[] args){         List&lt;String&gt; someList = new ArrayList&lt;&gt;();         IntStream.range(1, 10000).forEach(i-&gt;someList.add(Integer.toString(i)));         Test testArray = new Test(someList);         long cur = System.currentTimeMillis();         testArray.eliminateEachNth(3);         System.out.println("array list took " + (System.currentTimeMillis() - cur) + "millis");         System.out.println(someList);         List&lt;String&gt; anotherList = new LinkedList&lt;&gt;();         IntStream.range(1, 10000).forEach(i-&gt;anotherList.add(Integer.toString(i)));         Test testLinked = new Test(anotherList);         cur = System.currentTimeMillis();         testLinked.eliminateEachNth(3);         System.out.println("linked list took " + (System.currentTimeMillis() - cur) + "millis");         System.out.println(anotherList);      } }
How do I write a correct micro-benchmark in Java? How do you write (and run) a correct micro-benchmark in Java?  I'm looking for some code samples and comments illustrating various things to think about.  Example: Should the benchmark measure time/iteration or iterations/time, and why?  Related:
Edit:  Of course my real code doesn't look exactly like this. I tried to write semi-pseudo code to make it more clear of whay I wanted to do.  Looks like it just messed things up instead.  So, what I actually would like to do is this:  Method&lt;Interface1&gt;(); Method&lt;Interface2&gt;(); Method&lt;Interface3&gt;(); ...   Well ... I thought that maybe I could turn it into a loop using reflection. So the question is: How how do I do it. I have very shallow knowledge of reflection. So code examples would be great.  The scenario looks like this:  public void Method&lt;T&gt;() where T : class {} public void AnotherMethod() {     Assembly assembly = Assembly.GetExecutingAssembly();      var interfaces = from i in assembly.GetTypes()     where i.Namespace == "MyNamespace.Interface" // only interfaces stored here     select i;      foreach(var i in interfaces)     {         Method&lt;i&gt;(); // Get compile error here!     }       Original post:  Hi!  I'm trying to loop through all interfaces in a namespace and send them as arguments to a generic method like this:  public void Method&lt;T&gt;() where T : class {} public void AnotherMethod() {     Assembly assembly = Assembly.GetExecutingAssembly();      var interfaces = from i in assembly.GetTypes()     where i.Namespace == "MyNamespace.Interface" // only interfaces stored here     select i;      foreach(var interface in interfaces)     {         Method&lt;interface&gt;(); // Get compile error here!     } }   The error I get is "Type name expected, but local variable name found". If I try  ...     foreach(var interface in interfaces)     {         Method&lt;interface.MakeGenericType()&gt;(); // Still get compile error here!     } }   I get "Cannot apply operator '&lt;' to operands of type 'method group' and 'System.Type'" Any idea on how to get around this problem? I have a bathroom door that is quite loud when operated. And when someone goes to the bathroom at night, it innevatibly wakes someone up (and baby room is just across from the bathroom!) there are 3 components of noise, and I was wondering if there is an alternative to fixing them:   door bangs against the jamb (this is fixed with simple foam bumpers) latch mechanism makes a loud CLUNK when door is pushed closed (I was able to dampen it just a bit by putting foam inside strike plate, but it is still quite loud) lock button also makes a CLUNK when the knob is turned and it is released (this can be battled by replacing with a mechanism that needs to be manually opened [twist instead of push] but it is less convenient, and I would prefer something that automatically unlocks)   Any suggestions as to a knob that has a dampening of the latch and lock button? I have only found one youtube video of my ideal handle, but there is no information on how it works, where to buy it, or anything else: So there are several types of transistors:   BJT JFET MOSFET   Combine all that with the various flavors of each (NPN, PNP, enhancement mode, depletion mode, HEXFET, etc) and you've got a wide array of parts, many of which are capable of accomplishing the same job.  Which type is best suited for which application?  Transistors are used as amplifiers, digital logic switches, variable resistors, power supply switches, path isolation, and the list goes on.  How do I know which type is best suited for which application?  I'm sure there are cases where one is more ideally suited than another.  I admit that there is some amount of subjectivity/overlap here, but I'm certain that there is a general consensus about which category of applications each of the transistor types listed (and those I left off) is best suited for? For example, BJTs are often used for analog transistor amplifiers and MOSFETs are generally used for digital switching.  PS - If this needs to be a Wiki, that's fine if someone would like to convert it for me Is it (theoretically) physically possible to project an image into thin air? rewrite access to collection to avoid "double" finding The Ubuntu installer does not allow me to install on NTFS partitions, but certain circumstances requires me to do so. Is it possible? Last night, I was using Chrome just nicely, but this morning, I can't even start Google Chrome as it immediately crashes. I have already tried a clean uninstall and reinstall of Google Chrome but still the same error pops up (it does not happen while I'm opening Google Chrome. I woke up and only then realized I can't open my Chrome and it keeps popping up saying that Google Chrome has stopped working.)  OS : Win 7 64-bit  Here is the detail of the crashes  Problem signature:  Problem Event Name:    APPCRASH   Application Name:    chrome.exe    Application Version:    35.0.1916.114 Application Timestamp:    53726019    Fault Module Name:    chrome.dll   Fault Module Version:    35.0.1916.114   Fault Module Timestamp:    53725d18    Exception Code:    c0000005    Exception Offset:    00728bc8      OS Version:    6.1.7600.2.0.0.768.3    Locale ID:    17417    Additional Information 1:    0a9e    Additional Information 2:    0a9e372d3b4ad19135b953a78882e789    Additional Information 3:    0a9e    Additional Information 4:    0a9e372d3b4ad19135b953a78882e789     Any help that will solve this problems is greatly appreciated. What is the meaning of equation of a circle or equation of a cube? We have an equation of a Circle $$x^2 + y^2 = 1$$ and equation of a Cube $${||x-y|+|x+y|-2z|+||x-y|+|x+y|+2z|=1}$$  When I substitute x,y in first equation or x,y,z in the second equation then the equations are said to be satisfied when LHS and RHS are equal.  I have a quick question. If the first equation or second equation get satisfied, because LHS becomes equal to RHS, then those values of x and y of first equation are said to be lying on the circumference of the circle and not inside or outside of the circle and x,y,z of the second equation are said to be lying on the surface of the cube and not on the inside and not on the circle of the cube. Correct? Where can I find the Ivory Claw to open a door in Reachwater Rock? Shouldn't rep gains from old questions & answers eventually stop (or at-least reduce)? WPF DataGrid : CanContentScroll property causing odd behavior What happens when a caster targets an object that looks like a creature with a spell that targets only creatures? I am on a multiplayer Minecraft realm in 1.16 and I was wondering if there was any way to set a chest's Items to a player's entire Inventory including the offhand and armor slots. Using data modify &lt;chest coordinates&gt; Items set from entity &lt;player&gt; Inventory, I was only able to copy over the hotbar and the top two rows of a player's inventory. I honestly don't care if it takes 50 command blocks, any response is gladly appreciated. Performance difference between dot notation versus method call in Objective-C You can use a standard dot notation or a method call in Objective-C to access a property of an object in Objective-C.  myObject.property = YES;   or  [myObject setProperty:YES];   Is there a difference in performance (in terms of accessing the property)? Is it just a matter of preference in terms of coding style? Cascading Drop down in SharePoint Online I'm trying to implement cascading drop down for list in SharePoint online  I have 3 different list with name Countries , States, cities.  and the master list Address in which I have Fields Country , State, City.  I'm trying to display Sates for selected country. and City for selected States in SharePoint Online list Which version of Ubuntu will work on my PowerPC? I'm using iMac PowerPC G5 1.8 GHz, 1GB RAM, 160GB HDD, and 10.5.4 Leopard OS.  I want to run Ubuntu on my iMac. Please can anyone tell me which version will run in my system? How do I remove Ubuntu's password requirement? Last login: Mon Jun  7 22:43:40 on ttys000 samadams@Sams-MacBook-Pro-2 ~ % diskutil cs list No CoreStorage logical volume groups found samadams@Sams-MacBook-Pro-2 ~ % diskutil list /dev/disk0 (internal, physical):    #:                       TYPE NAME                    SIZE       IDENTIFIER    0:      GUID_partition_scheme                        *121.3 GB   disk0    1:                        EFI ⁨NO NAME⁩                 536.9 MB   disk0s1                     (free space)                         60.5 GB    -    2:                 Apple_APFS ⁨Container disk1⁩         60.1 GB    disk0s2  /dev/disk1 (synthesized):    #:                       TYPE NAME                    SIZE       IDENTIFIER    0:      APFS Container Scheme -                      +60.1 GB    disk1                                  Physical Store disk0s2    1:                APFS Volume ⁨MacOS Big Sur - Data⁩    30.0 GB    disk1s1    2:                APFS Volume ⁨Preboot⁩                 233.2 MB   disk1s2    3:                APFS Volume ⁨Recovery⁩                652.6 MB   disk1s3    4:                APFS Volume ⁨VM⁩                      1.1 GB     disk1s4    5:                APFS Volume ⁨MacOS Big Sur⁩           24.4 GB    disk1s5    6:              APFS Snapshot ⁨com.apple.os.update-...⁩ 24.4 GB    disk1s5s1    7:                APFS Volume ⁨Untitled⁩                860.2 KB   disk1s7 If $\sum_na_n=\infty$ and $a_n\downarrow 0$ then $\sum\limits_n\min(a_{n},\frac{1}{n})=\infty$ If $\sum_na_n=\infty$ and $a_n\downarrow 0$ then $\sum\limits_n\min(a_{n},\frac{1}{n})=\infty$     My  idea:  $$b_{n}=\min(a_{n},\tfrac{1}{n})\Longrightarrow b_{n}\le a_{n},b_{n}\le\tfrac{1}{n}$$ then I don't know how to go on. Order a MySQL table by two columns How do I sort a MySQL table by two columns? What I want are articles sorted by highest ratings first, then most recent date.  As an example, this would be a sample output (left # is the rating, then the article title, then the article date)  +================+=============================+==============+ | article_rating | article                     | article_time | +================+=============================+==============+ | 50             | This article rocks          | Feb 4, 2009  | +----------------+-----------------------------+--------------+ | 35             | This article is pretty good | Feb 1, 2009  | +----------------+-----------------------------+--------------+ | 5              | This Article isn't so hot   | Jan 25, 2009 | +================+=============================+==============+  The relevant SQL I'm using is: ORDER BY article_rating, article_time DESC  I can sort by one or the other, but not both.