I have a String in Java called Kiran<[email protected]>
. I want to get String just [email protected] by removing other content.
String s1= kiran<[email protected]>
Output should be [email protected]
Please help me out in solving this.
trim() . trim() removes spaces before the first character (which isn't a whitespace, such as letters, numbers etc.) of a string (leading spaces) and also removes spaces after the last character (trailing spaces).
The trim() method in Java String is a built-in function that eliminates leading and trailing spaces. The Unicode value of space character is '\u0020'. The trim() method in java checks this Unicode value before and after the string, if it exists then removes the spaces and returns the omitted string.
How to use filter() method in Java 8. Java 8 Stream interface introduces filter() method which can be used to filter out some elements from object collection based on a particular condition. This condition should be specified as a predicate which the filter() method accepts as an argument.
The idea is to use the deleteCharAt() method of StringBuilder class to remove first and the last character of a string. The deleteCharAt() method accepts a parameter as an index of the character you want to remove.
If you are trying to parse email addresses, I'd recommend to use the InternetAddress class. It is part of Java EE (if you are using Java SE you need to add the javax.mail dependency).
That class is able to parse an String containing an email address like yours.
String s1 = "kiran<[email protected]>";
InternetAddress address = new InternetAddress(s1);
String email = address.getAddress();
I think this way:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With