#Is there a shorter way to do this?
1 messages · Page 1 of 1 (latest)
<@&987246399047479336> please have a look, thanks.
While you are waiting for getting help, here are some tips to improve your experience:
If nobody is calling back, that usually means that your question was not well asked and hence nobody feels confident enough answering. Try to use your time to elaborate, provide details, context, more code, examples and maybe some screenshots. With enough info, someone knows the answer for sure.
Don't forget to close your thread using the command </help-thread close:1027500463647621170> when your question has been answered, thanks.
Nope
That's basically it, tbh.
Guava or Apache Commons might have some utility to do this for you, but no need to import an entire library for a single function.
Theres nothing defined in java's API for that. And a function like that typically would violate some programming 'rule' that says a function should only do one task. Hence you would have 1 function to uppercase, and one to trim it down. You can write your own method like
public static String ucFirst(String s) {
if (s == null) return null;
if (s.length() <= 1) return s.toUpperCase();
return s.substring(0,1).toUpperCase() + s.substring(1).toLowerCase();
}```
then
```java
ucFirst(name).substring(0, 4) // missing error checking on substring upper bound and non null
Thank you all!