Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[20210224] StringUtils defaultString, StringJoiner #49

Open
JuHyun419 opened this issue Feb 24, 2021 · 0 comments
Open

[20210224] StringUtils defaultString, StringJoiner #49

JuHyun419 opened this issue Feb 24, 2021 · 0 comments
Labels

Comments

@JuHyun419
Copy link
Owner

JuHyun419 commented Feb 24, 2021

apache commons - StringUtils.defaultString()

    // pom.xml
    <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-lang3</artifactId>
        <version>3.8.1</version>
    </dependency>


    public static String defaultString(String str) {
        return defaultString(str, "");
    }

    public static String defaultString(String str, String defaultStr) {
        return str == null ? defaultStr : str;
    }

StringJoiner(Java8 util) ... String의 join과 비슷

    public static String solution(String s) {
        String[] sSplit = s.split(" ");
        StringJoiner stringJoiner = new StringJoiner(",");

        for (String str : sSplit) {
            String firstWordToUpper = str.substring(0, 1).toUpperCase();
            String otherWord = str.substring(1).toLowerCase();
            stringJoiner.add(firstWordToUpper + otherWord);
        }

        return stringJoiner.toString();
    }

    public static void main(String[] args) {
        String str = "3people unFollowed me";
        System.out.println(solution(str));
    }

3people,Unfollowed,Me

@JuHyun419 JuHyun419 added the Java label Feb 24, 2021
@JuHyun419 JuHyun419 changed the title [20210224] StringUtils defaultString(null 처리) [20210224] StringUtils defaultString, StringJoiner Feb 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant