I'm having problem with my delete command of my array list while I'm iterating it.  How can I resolve the ConcurrentModificationException?  protected void deleteModeOfPayment(List&lt;List&lt;String&gt;&gt; AllModeOfPayment) {     int ctr=0;     List&lt;String&gt; thePayments =new ArrayList&lt;String&gt;();     Iterator&lt;List&lt;String&gt;&gt; ia=allModeOfPayment.iterator();     while(ia.hasNext()){         thePayments=ia.next();         String refOne= thePayments.get(1).toString().trim();         if(refOne.equals(referenceIdentity)){             log.d("ALVIN","ITEM TO BE DELETE FOUND");             allModeOfPayment.remove(ctr);         }         else{             ctr++;             log.d("ALVIN","ITEM TO BE DELETE NOT FOUND");}         }     } }
We all know you can't do the following because of ConcurrentModificationException:  for (Object i : l) {     if (condition(i)) {         l.remove(i);     } }   But this apparently works sometimes, but not always. Here's some specific code:  public static void main(String[] args) {     Collection&lt;Integer&gt; l = new ArrayList&lt;&gt;();      for (int i = 0; i &lt; 10; ++i) {         l.add(4);         l.add(5);         l.add(6);     }      for (int i : l) {         if (i == 5) {             l.remove(i);         }     }      System.out.println(l); }   This, of course, results in:  Exception in thread "main" java.util.ConcurrentModificationException   Even though multiple threads aren't doing it. Anyway.  What's the best solution to this problem? How can I remove an item from the collection in a loop without throwing this exception?  I'm also using an arbitrary Collection here, not necessarily an ArrayList, so you can't rely on get.
Chen weibull distribution $M= \{ A \in Mat_{2 \times 2}{\mathbb{R}}| \det(A)=1 \}$ is homeomorphic to $S^{1} \times \mathbb{R}^{2}$ How to delete all lines that do NOT contain a certain word in Vim? In vim I can delete all lines that contain the word "price" with this  :g /price/d   How can I delete all lines that do NOT contain the word "price"? How to keep any Window "Always on Top"? Some software have an option for their window to be "Always on Top". Is there any way to get the same functionality for any window. Let me give an example where this would be useful.  Suppose I have a small browser window with real time stats from a game. The window is automatically updated at the rate of once every 10 seconds. I would like the small window to be always on top. so that I can just look at it whenever I want to, without actually going to it and at the same time I could continue working in my main application, which is at full screen.  Is there any Windows hack or App which can give me this functionality? Choosing between LM and GLM for a log-transformed response variable I'm trying to understand the philosophy behind using a Generalized Linear Model (GLM) vs a Linear Model (LM). I've created an example data set below where:  $$\log(y) = x + \varepsilon $$   The example does not have the error $\varepsilon$ as a function of the magnitude of $y$, so I would assume that a linear model of the log-transformed y would be the best. In the example below, this is indeed the case (I think) - since the AIC of the LM on the log-transformed data is lowest. The AIC of the Gamma distribution GLM with a log-link function has a lower sum of squares (SS), but the additional degrees of freedom result in a slightly higher AIC. I was surprised that the Gaussian distribution AIC is so much higher (even though the SS is the lowest of the models).   I am hoping to get some advice on when one should approach GLM models - i.e. is there something I should look for in my LM model fit residuals to tell me that another distribution is more appropriate? Also, how should one proceed in selecting an appropriate distribution family.   Many thanks in advance for your help.  [EDIT]: I have now adjusted the summary statistics so that the SS of the log-transformed linear model is comparable to the GLM models with the log-link function. A graph of the statistics is now shown.  Example  set.seed(1111) n &lt;- 1000 y &lt;- rnorm(n, mean=0, sd=1) y &lt;- exp(y) hist(y, n=20) hist(log(y), n=20)  x &lt;- log(y) - rnorm(n, mean=0, sd=1) hist(x, n=20)  df  &lt;- data.frame(y=y, x=x) df2 &lt;- data.frame(x=seq(from=min(df$x), to=max(df$x),,100))   #models mod.name &lt;- "LM" assign(mod.name, lm(y ~ x, df)) summary(get(mod.name)) plot(y ~ x, df) lines(predict(get(mod.name), newdata=df2) ~ df2$x, col=2)  mod.name &lt;- "LOG.LM" assign(mod.name, lm(log(y) ~ x, df)) summary(get(mod.name)) plot(y ~ x, df) lines(exp(predict(get(mod.name), newdata=df2)) ~ df2$x, col=2)  mod.name &lt;- "LOG.GAUSS.GLM" assign(mod.name, glm(y ~ x, df, family=gaussian(link="log"))) summary(get(mod.name)) plot(y ~ x, df) lines(predict(get(mod.name), newdata=df2, type="response") ~ df2$x, col=2)  mod.name &lt;- "LOG.GAMMA.GLM" assign(mod.name, glm(y ~ x, df, family=Gamma(link="log"))) summary(get(mod.name)) plot(y ~ x, df) lines(predict(get(mod.name), newdata=df2, type="response") ~ df2$x, col=2)  #Results model.names &lt;- list("LM", "LOG.LM", "LOG.GAUSS.GLM", "LOG.GAMMA.GLM")  plot(y ~ x, df, log="y", pch=".", cex=3, col=8) lines(predict(LM, newdata=df2) ~ df2$x, col=1, lwd=2) lines(exp(predict(LOG.LM, newdata=df2)) ~ df2$x, col=2, lwd=2) lines(predict(LOG.GAUSS.GLM, newdata=df2, type="response") ~ df2$x, col=3, lwd=2) lines(predict(LOG.GAMMA.GLM, newdata=df2, type="response") ~ df2$x, col=4, lwd=2) legend("topleft", legend=model.names, col=1:4, lwd=2, bty="n")   res.AIC &lt;- as.matrix(     data.frame(         LM=AIC(LM),         LOG.LM=AIC(LOG.LM),         LOG.GAUSS.GLM=AIC(LOG.GAUSS.GLM),         LOG.GAMMA.GLM=AIC(LOG.GAMMA.GLM)     ) )  res.SS &lt;- as.matrix(     data.frame(         LM=sum((predict(LM)-y)^2),         LOG.LM=sum((exp(predict(LOG.LM))-y)^2),         LOG.GAUSS.GLM=sum((predict(LOG.GAUSS.GLM, type="response")-y)^2),         LOG.GAMMA.GLM=sum((predict(LOG.GAMMA.GLM, type="response")-y)^2)     ) )  res.RMS &lt;- as.matrix(     data.frame(         LM=sqrt(mean((predict(LM)-y)^2)),         LOG.LM=sqrt(mean((exp(predict(LOG.LM))-y)^2)),         LOG.GAUSS.GLM=sqrt(mean((predict(LOG.GAUSS.GLM, type="response")-y)^2)),         LOG.GAMMA.GLM=sqrt(mean((predict(LOG.GAMMA.GLM, type="response")-y)^2))     ) )  png("stats.png", height=7, width=10, units="in", res=300) #x11(height=7, width=10) par(mar=c(10,5,2,1), mfcol=c(1,3), cex=1, ps=12) barplot(res.AIC, main="AIC", las=2) barplot(res.SS, main="SS", las=2) barplot(res.RMS, main="RMS", las=2) dev.off() I have noticed that some browsers (in particular, Firefox and ) are very zealous in using cached copies of .css and .js files, even between browser sessions. This leads to a problem when you update one of these files, but the user's browser keeps on using the cached copy. What is the most elegant way of forcing the user's browser to reload the file when it has changed? Ideally, the solution would not force the browser to reload the file on every visit to the page.  I have found  and  suggestion to be useful. It turns out there is a term for this: auto-versioning. I have posted a new answer below which is a combination of my original solution and John's suggestion. Another idea that was suggested by SCdF would be to append a bogus query string to the file. (Some Python code, to automatically use the timestamp as a bogus query string, was .) However, there is some discussion as to whether or not the browser would cache a file with a query string. (Remember, we want the browser to cache the file and use it on future visits. We only want it to fetch the file again when it has changed.) If we have an implicit surface $g(x, y, z)=...$, the gradient is a normal vector. But why? Do I have to start with tangent vectors and then show the gradient is perpendicular? Not sure how to approach this. Equivalent of "both" when referring to three or more items? Quantum Field Theory from a mathematical point of view I'm a student of mathematics with not much background in physics. I'm interested in learning Quantum field theory from a mathematical point of view.  Are there any good books or other reference material which can help in learning about quantum field theory? What areas of mathematics should I be familiar with before reading about Quantum field theory? How does the human eye knows how far the object from which the photon was reflected? A photon is emitted from a source and reflected off an object (or objects) until it hits the human eye. The color of the object we see depends on the photon wavelength. If photon travels with constant speed how does the human eye know how far the object from which the photon was reflected? My wife is an Indian national with an Indian passport. She holds an indefinite leave to remain in the UK (permanent residence card). Does she need to apply for a Schengen visa before travelling to France or any other Schengen countries? Georeferencing scanned map using ArcMap? Found the alternative form: $\sum _{k=1}^\infty ((1-\frac{1}{k})^{k})^k$. Tried various criteria, no luck so far. In D&amp;D 5, the saving throws for spells has the following formula:  The DC is set to 8 + prof bonus + magical stat bonus.  The target then makes a saving throw, adding their stat bonus and hoping to get above that DC.  Instead of having the defender roll the saving throw, we would like the attacker to roll the attack against the "defense" of the monster. (Mainly to make play by post run smoother)  Would this mean that the attacker just rolls d20+prof + magic stat bonus, and they try to get a number which is higher than 8+ monster def stat bonus, or is there a different formula which better maintains the math? (This math sounds wrong to me, so I assume there is a better formula) How to Compact geodatabases in multiple directories using ArcPy? I am trying to write a script to walk through all folders in my workspace and find and compact all geodatabases in my workspace.  I feel like I'm on the right track but I am stuck.  import acrpy, os from arcpy import env  arcpy.env.workspace "C:"  for (path, dirs, files) in os.walk(arcpy.env.workspace)     for file in files         if ".gdb" in file:         workspaces = arcpy.ListWorkspaces("*", "FileGDB")             for workspace in workspaces:             arcpy.Compact_management(workspace)   I am using ArcGIS 10.2.2 for Desktop. The question is how can I exclude an object from the freestyle render?  What I need to do is create a Clay render with the wire only on the airplane.  My scene is simple I only have two objects the "Toy Plane" and the "floor". For the Clay render I only override the materials to a simple clay material and done.    But this happens when I use freestyle. How can I tell freestyle to ignore the "Floor"? How to create and design hoops net and attach ot to a hoop? How do I calculate the probability density function for a joint beta + uniform distribution? The PDF of a Beta distribution is $$ f_X(x) = {{x^{a-1}(1-x)^{b-1}}\over {B(a,b)}}  $$ and CDF $$ F_X(x) =  I_x(a,b) $$ The PDF of a uniform distribution is $$ f_Y(y) =  {1 \over {b-a}} \space for \space  x \in [a,b] $$ and CDF $$ { x - a} \over {b - a} $$ I've know that if X and Y are two independent, continuous random variables, described by probability density functions above of $f_X(x)$ and $f_Y(x)$ then probability density function of $Z = XY$ is $$  f_Z(z) = \int_\infty^\infty f_X(x)f_Y({z\over x}){1\over abs(x)}dx  $$ but I'm struggling with the algebra to get  from this to the PDF and the CDF of the joint distribution. I'm using the uniform distribution between 0 and 1. I know the minimum number of reference letters required at many U.S. PhD programs in the STEM fields is three -- and that it is also not uncommon for someone to submit a fourth letter.  What about a fifth letter?  Would a fifth letter of recommendation be perceived as "too many"? How can I discover any USB storage devices and/or CD/DVD writers available at a given time (using C# .Net2.0).  I would like to present users with a choice of devices onto which a file can be stored for physically removal - i.e. not the hard drive.