LoginSignup
0
0

ApexのString.join()の代わり

Posted at

String.join()は間に空文字列があるとseparatorが連続してしまうので代わりに以下

  private static String join(List<String> values, String separator) {
    String ret = '';
    for (String value : values) {
      if (String.isEmpty(value)) {
        continue;
      }
      if (!String.isEmpty(ret)) {
        ret += separator;
      }
      ret += value;
    }
    return !String.isEmpty(ret) ? ret : null;
  }
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0