Java String Snake Case toSnakeCase(String str)

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

Description

Convert a string to snake_case

License

Open Source License

Parameter

Parameter Description
str a parameter

Declaration

public static String toSnakeCase(String str) 

Method Source Code

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

public class Main {
    /**/*from  w  w w  .j a  v a  2  s . c  o m*/
     * Convert a string to snake_case
     * @param str
     * @return
     */
    public static String toSnakeCase(String str) {
        return str.replaceAll("([a-z])([A-Z])", "$1_$2").toLowerCase();
    }
}

Related

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