Java String Snake Case toSnakeCase(String src)

Here you can find the source of toSnakeCase(String src)

Description

to Snake Case

License

Open Source License

Declaration

public static String toSnakeCase(String src) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static String toSnakeCase(String src) {

        String dst = new String();
        for (int i = 0; i < src.length(); i++) {
            char c = src.charAt(i);
            if ('A' <= c && c <= 'Z') {
                c += 32;//from  w w w.  j  a v a 2s  .c  o m
                if (i != 0) {
                    dst += '_';
                }
            }
            dst += c;
        }

        return dst;
    }
}

Related

  1. toSnakeCase(String camelCase)
  2. toSnakeCase(String s)
  3. toSnakeCase(String str)
  4. toSnakeCase(String str)
  5. toSnakeCase(String str, boolean capitalize, Boolean upper)