Remove letter “e” in the end of each word Java

  • A+
Category:Languages

Need help. Remove letter “e” in the end of each word if word length > 1. I have tried to do it via strig split and toCharArray, but I can't convert array after removing to string. Thank you in advance.

public class RemoveE {     public static void main(String args[]) {         String str = "like row lounge dude top";         String[] words = str.split("//s|[,.;:]");         for (String subStr : words) {             if (subStr.endsWith("e"))                 subStr = subStr.substring(0, subStr.length() - 1);             String finalString = new String(subStr);             System.out.println(finalString);         } } } 

 


It would be much simpler if you do it via regex like this

finalString = str.replaceAll("e//b", ""); 

This is giving following output:

lik row loung dud top 

PS: This solution assumes that you would like to drop even a single e in string since in the question, we're using if (subStr.endsWith("e")) which will also remove a single e in the String.

Comment

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: