Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8908603
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T03:13:20+00:00 2026-06-15T03:13:20+00:00

The following routine behaves differently on WIN XP x32, JAVA Version 7 Update 9

  • 0

The following routine behaves differently on WIN XP x32, JAVA Version 7 Update 9 and on WIN7 x64, JAVA version 6 Update 32.

private int getNrOfMatches(String temp, String regex) {
            String prev;
            int nrOfIterations = -1;
            do {
                nrOfIterations++;
                prev = temp;
                temp = temp.replaceFirst(regex, " ");
            } while (temp != prev);
            return nrOfIterations;
        }

replaceFirst() returns the same object if it didn’t modify anything and the loop ends on WIN XP. On Win7 it goes on an endless loop as != will always return false because the routine returns a new object even if it didn’t change anything.
Using .equals() instead of != solves this issue but my question is can anyone explain this behaviour?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T03:13:22+00:00Added an answer on June 15, 2026 at 3:13 am

    So to take a stab at answering the part of the question of why it is working some of the time. The JVM has some cleaver optimizations that try and reuse references of the same string instead of creating new references with the same content. It is possible that while running on Win XP your JVM has these optimizations while your Win 7 does not (are they the same version?)

    This SO Question covers this topic fairly well and the accepted answer talks about ways to actually add strings to a constant pool (calling .intern()). In terms of determining equality, this is not a stable solution because the JVM will always take priority over any memory management choices you make in your Java code.

    Also digging into the JVM options I did find this interesting option (-XX:+UseStringCache) and this SO question that talks about what it does. Maybe your Win XP JVM has the -server optimizations while your Win 7 does not?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given the following routine: private static object ParseNumber(string token, FieldDefinition def) { if (def.Fraction
I have the following routine that dumps a DataTable into an Excel worksheet. private
I have the following code: #include <iostream> #include <string> #include sqlite3.h int main() {
I have the following MySQL routine: DELIMITER $$ CREATE DEFINER=`root`@`%` PROCEDURE `getGroupOrders`(grp INT, ord
I have the following configured within my IContainer Initialize routine: x.For<IDbConnection>().Use<SqlConnection>().Ctor<string>().Is(MY_SQL_CONNECTION_STRING); Here's the constructor
Searching online, I have found the following routine for calculating the sign of a
In my Fortran code I made the following call to the dnrm2 routine: d
When I try to run a routine I get the following error: Error Code:
I've implemented url routing with the following rule: string virtualPath = ~/ + requestContext.RouteData.Values[page].ToString();
We are using the following routine (on Linux, with libudev) to read data from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.