title: Most efficient way to convert Enum values into comma seperated String
body: <p>I have a java class in which I store an Enum.(shown at the bottom of this question) In this enum, I have a method named <strong>toCommaSeperatedString()</strong> who returns a comma separated String of the enums values. I am using a StringBuilder after reading some information on performance in this question <a href="https://stackoverflow.com/questions/355089/difference-between-stringbuilder-and-stringbuffer?page=1&amp;tab=votes#tab-top">here</a>. </p>
  
  <p>Is the way I am converting this enum's values into a commaSeperatedString the most efficient way of doing so, and if so, what would be the most efficient way to remove the extra comma at the last char of the String?</p>
  
  <p>For example, my method returns <code>123, 456,</code> however I would prefer <code>123, 456</code>. If I wanted to return <code>PROPERTY1, PROPERTY2</code> I could easily use Apache Commons library StringUtils.join(), however, I need to get one level lower by calling the <code>getValue</code> method when I am iterating through the String array.</p>
  
  <pre><code>public class TypeEnum {
      public enum validTypes {
          PROPERTY1("123"),
          PROPERTY2("456");
  
          private String value;
  
          validTypes(String value) {
              this.value = value;
          }
  
          public String getValue() {
              return value;
          }
  
          public static boolean contains(String type) {
              for (validTypes msgType : validTypes.values()) {
                  if (msgType.value.equals(type)) {
                      return true;
                  }
              }
              return false;
          }
  
          public static String toCommaSeperatedString() {
              StringBuilder commaSeperatedValidMsgTypes = new StringBuilder();
              for(validTypes msgType : validTypes.values()) {
                  commaSeperatedValidMsgTypes.append(msgType.getValue() + ", ");
              }
              return commaSeperatedValidMsgTypes.toString();
          }
      }
  }
  </code></pre>