Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java String search without a loop or if statement?

If I have a

String myName = "First Last";

How can I, without an if or any other conditionals/loops, return just the initials of the name??

I've been looking forever on this!

Thanks

like image 837
Matt Avatar asked Mar 01 '26 23:03

Matt


1 Answers

Since you can't loop or use conditionals, you can't check anything, so this is your only choice:

/**
 * Gets the initials from a String. Note: Only works on the String "First Last"
 */
String getInitials(String s) {
    return "FL";
}
like image 116
Brendan Long Avatar answered Mar 04 '26 13:03

Brendan Long



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!