String replace with callback in Java (like in JavaScript)

When you use JavaScript a lot you are more or less used to the callback-hell, but i hope you love the benefits of passing functions around as much as i do.

For example when replacing a portion of a string:

"test6test12test".replace(/\d+/g, function(str){
  return parseInt(str) * 2;
});

When doing such things in Java it can be a bit of a hassle, but Lambda-Expressions to the rescue!

Leave a Reply

Your email address will not be published. Required fields are marked *