Java Collection Join join(Collection strings, String delimiter)

Here you can find the source of join(Collection strings, String delimiter)

Description

join

License

Apache License

Declaration

public static String join(Collection<?> strings, String delimiter) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.util.Collection;

public class Main {
    public static String join(String[] strings, String delimiter) {
        StringBuilder sb = new StringBuilder();

        for (String string : strings) {
            if (string == null) {
                string = "";
            }/*from   ww w  .  ja v  a  2s.co  m*/
            if (sb.length() > 0) {
                sb.append(delimiter).append(string);
            } else {
                sb.append(string);
            }
        }

        return sb.toString();
    }

    public static String join(String[] strings, char delimiter) {
        StringBuilder sb = new StringBuilder();

        for (String string : strings) {
            if (string == null) {
                string = "";
            }
            if (sb.length() > 0) {
                sb.append(delimiter).append(string);
            } else {
                sb.append(string);
            }
        }

        return sb.toString();
    }

    public static String join(Collection<?> strings, char delimiter) {
        StringBuilder sb = new StringBuilder();

        for (Object string : strings) {
            if (string == null) {
                string = "";
            }
            if (sb.length() > 0) {
                sb.append(delimiter).append(string.toString());
            } else {
                sb.append(string.toString());
            }
        }

        return sb.toString();
    }

    public static String join(Collection<?> strings, String delimiter) {
        StringBuilder sb = new StringBuilder();

        for (Object string : strings) {
            if (string == null) {
                string = "";
            }
            if (sb.length() > 0) {
                sb.append(delimiter).append(string.toString());
            } else {
                sb.append(string.toString());
            }
        }

        return sb.toString();
    }

    public static String join(Number[] strings, String delimiter) {
        StringBuilder sb = new StringBuilder();

        for (Object string : strings) {
            if (string == null) {
                string = "";
            }
            if (sb.length() > 0) {
                sb.append(delimiter).append(string.toString());
            } else {
                sb.append(string.toString());
            }
        }

        return sb.toString();
    }

    public static String join(Number[] strings, char delimiter) {
        StringBuilder sb = new StringBuilder();

        for (Object string : strings) {
            if (string == null) {
                string = "";
            }
            if (sb.length() > 0) {
                sb.append(delimiter).append(string.toString());
            } else {
                sb.append(string.toString());
            }
        }

        return sb.toString();
    }
}

Related

  1. join(Collection s)
  2. join(Collection s, String delimiter)
  3. join(Collection s, String delimiter)
  4. join(Collection s, String delimiter)
  5. join(Collection strings, String delimiter)
  6. join(Collection strings, String separator)
  7. join(Collection strings, String separator)
  8. join(Collection strings, String separator)
  9. join(Collection strs)