Java - Can i have a faster performance for this loop ?

Posted by Brad on Stack Overflow See other posts from Stack Overflow or by Brad
Published on 2010-12-26T20:25:00Z Indexed on 2010/12/26 20:54 UTC
Read the original article Hit count: 157

Filed under:
|
|

I am reading a book and deleting a number of words from it. My problem is that the process takes long time, and i want to make its performance better(Less time), example :

Vector<String> pages = new Vector<String>();  // Contains about 1500 page, each page has about 1000 words.
Vector<String> wordsToDelete = new Vector<String>();  // Contains about 50000 words.

for( String page: pages ) {
    String pageInLowCase = page.toLowerCase();

    for( String wordToDelete: wordsToDelete ) {
        if( pageInLowCase.contains( wordToDelete ) )
            page = page.replaceAll( "(?i)\\b" + wordToDelete + "\\b" , "" );
    }

    // Do some staff with the final page that does not take much time.
}

This code takes around 3 minutes to execute. If i skipped the loop of replaceAll(...) i can save more than 2 minutes. So is there a way to do the same loop with a faster performance ?

© Stack Overflow or respective owner

Related posts about java

Related posts about Performance