• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Bear Bibeault
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Piet Souris
  • salvin francis
  • Stephan van Hulst
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Jj Roberts

Java Get Ngrams Method - Performance Improvements

 
Ranch Hand
Posts: 189
14
Hibernate Eclipse IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I’ve written a method to get the number of n-grams of a specified size n from a String.  For example, the number of 2-grams in the sentence “How now brown cow” is 3:

How now
now brown
Brown cow

Here is my method:





My concern is that the nested for loop here might adversely affect performance and that there would be a faster, more memory-efficient way to perform this operation.  Are there any suggestions?  Or are there any common libraries out there that perform this function that I've overlooked?
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic