JAVA - length() in a for loop Is it bad to use 'str.length()' in a for loop or any kind of loop? Does this make O(n^2) complexity? If it is bad, we can assign it to a variable and use the variable instead, right?
In Java, for a string x, what is the runtime cost of s.length()? Is it O(1) or O(n)? I've been told that code such as:  for (int i = 0; i &lt; x.length(); i++) {     // blah }   is actually O(n^2) because of the repeated calls to x.length(). Instead I should use:  int l = x.length(); for (int i = 0; i &lt; l; i++) {     // blah }   Is this true? Is string length stored as a private integer attribute of the String class? Or does String.length() really walk the whole string just to determine its length?
How to find an ellipse , given 2 passing points and the tangents at them? Please answer to a question , how to find an ellipse which passes the 2 given points and has the given tangents at them. And one related question is that the given condition can decide just one ellipse which satisfies it?  Thank you in advance.  Edit : May be , I can say the first answer (by Mr. André Nicolas) is for the general case. Is there no special case where only a finite set of ellipses satisfies the condition?  Edit : According to the answers and comments , I can compute an arbitrary chosen ellipse for my condition (using the method by Mr.Patrick Da Silva). But there are possibly many others which satisfy my conditions. Am I right? Why are map tiles being repeated? Using MapServer and Openlayers “I saw a dog” vs. “I have seen a dog” I saw a dog.       I have seen a dog.   What are the differences between them? Did these events happen on the same day? Populating cascading dropdown lists in JSP/Servlet ToC numbering problem What is the relationship between size of object with distance? How does the size/length of an object vary with distance?   Is it a logarithmic relationship? exponential? linear?   I plotted a curve of the size/length of an object for different distances from the camera, and the curve looked exponential/logarithmic. I was trying to understand the reasoning behind that. Web service - current time zone for a city? Is there a web service of some sort (or any other way) to pull a current time zone settings for a (US) city. For the parts of the country that don't follow the Daylight Saving Time and basically jump timezones when everyone else is switching summer/winter time... I don't fancy creating own database of the places that don't follow DST. Is there a way to pull this data on demand?   I need this for the database server (not for client workstations) - there entities stored in the database that have City, State as properties. I need know current timezone for these entities at any moment of time. Object emit light distance I created an object, and I wanted it to glow. I used to just place points of light around it, and parent them to it, but using the emit option in the materials seemed so much easier.  But when I gave it an a higher emit than 0, it went only a small distance before the light stopped. I turned it up to 200, and the object was white with light, but the light didn't go any farther. Oh and I changed the color, and nothing happened. Let $V=\{f : S \to \mathbb{R} \}$ be the set of all the functions $f : S \to \mathbb{R}$. Let $S=\{ 1,2,...,n$}, now my train of thought was that the basis of V must be a linearly independent set that Span V so somehow show that there is a set of functions on S that can compose as a linear combination and map to any number in $\mathbb{R}$. Any idea how to get a general answer for basis for dimension of V? I am trying to calculate the force of impact of a falling object. I did my egg drop project. I dropped the egg from 10m with a mass of 126kg and with the velocity of 14.1 m/s. Which formula should I use to calculate the force of impact? I found the kinetic energy first and later I used the following formula: $W=Fs$ to find the force of impact. Is that the right formula? single email limit exceeded salesforce very frequently..? my email limit is exceeded after sending 10-12 emails..what could be the problem..as i have seen the limit is 1000 emails/day.i am not able to find out what could be the problem..Can some give me some suggestions. As i also know we can send 10 emails in a single transaction.I am sending emails in a batch class.  I am calling this batch class on button click and filling emailList with emailsId's.                      String query='Select id from Lead';//No use of this query                     Batch_send_emails bse=new Batch_send_emails();                     bse.query=query;                                                         bse.resendEmails=emailList;                     database.executebatch(bse);           **Batch Class**           if(!resendEmails.isEmpty())           {               for(String s:resendEmails)                {                   emailsLeads.add(s);                }           }           Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();         mail.setToAddresses(emailsLeads);        // mail.setCcAddresses(ccAddresses);         String subject='GoToMeeting Invitation Details for '+subject;         String body='test';          mail.setHtmlBody(body);          mail.setSubject(subject);         Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });          } How far do you go with const?  Do you just make functions const when necessary or do you go the whole hog and use it everywhere?  For example, imagine a simple mutator that takes a single boolean parameter:  void SetValue(const bool b) { my_val_ = b; }   Is that const actually useful?  Personally I opt to use it extensively, including parameters, but in this case I wonder if it's worthwhile?  I was also surprised to learn that you can omit const from parameters in a function declaration but can include it in the function definition, e.g.:  .h file  void func(int n, long l);   .cpp file  void func(const int n, const long l)   Is there a reason for this? It seems a little unusual to me. Testing Whether a Binomial Distribution Fits Data I have a sample from a discrete distribution as such:   Type:          0   1   2   3   4   5     Occurrences:  88  12  52  43  21   5   My task is to test whether or not a Binomial Distribution (n=5,p) fits this data.   I understand that I'm meant to use hypothesis testing, and that the chi-square test is a staple for this sort of task. I looked at  but I'm still not sure how to set up the test. How do I do this? I need to clip a vector layer to the extent of a raster. It has to be very precise that's why I would not want to draw a polygon myself (and clip the two polygons). There seem to be some ways to clip a raster to a polygon but I have difficulties to find a solution to clip a polygon to a raster. I already tried to create a polygon out of my raster several times in ArcGIS and R, so I could clip the result. But every time it crashes because the raster is to big. There must be a simple way to solve this, and somehow I can just not see it at the moment.  How can I do this using GDAL? Combinatorics - Painting the Unit Squares of a 3x3 Square Why is vote time missing in the SE data dump and SEDE? Is there a particular reason why vote times are omitted in the data dump?  IMO this could be a very useful data-set. Is this one of the steps that was done to anonymize the data, or does it simply not exist? This would be a very good addition to future dumps to help build time-based relationships, which are currently very rigid and full of assumptions. I have multiple Ubuntu machines at home and a pretty slow internet connection, and sometimes multiple machines need to be updated at once (especially during new Ubuntu releases.)  Is there a way where only one of my machines needs to download the packages, and the other machines can use the first machine to get the debs?  Does it involve setting up my own local mirror?  Or a proxy server?  Or can it be made simpler? What does the "@" symbol do in SQL? I was browsing through the questions and noticed this:  SELECT prodid, issue FROM Sales  WHERE custid = @custid  AND datesold = SELECT MAX(datesold)               FROM Sales s               WHERE s.prodid = Sales.prodid                   AND s.issue = Sales.issue                   AND s.custid = @custid   I was wondering what the "@" does in front of custID?  Is it just a way of referencing the custID from the table being selected? How do I iterate through each element in an n-dimensional matrix in MATLAB? Inequality involving the sup of a function and its first and second derivatives