1、刚开始写scala,发现确实还是很不熟悉,api以及语法的使用都不是很简洁,这写出来跟java也没差多少。。。
献丑了
package spark /** * @ProjectName: cutter-point * @Package: spark * @ClassName: Demo1 * @Author: xiaof * @Description: ${description} * @Date: 2019/5/30 9:27 * @Version: 1.0 */ object Hello { //定义下滑转驼峰 def underlineToHump(str : String) : String = { var spStr : Array[String] = str.split("_") //循环这个数组 var result = "" var index = 0 for(i <- 0 to str.length - 1) { if(str.charAt(i) == '_') { index = 1 + i } else { if(i == index && i != 0) { result += str.charAt(i).toUpper } else { result += str.charAt(i) } } } result } /** * 驼峰转下滑 * @param str * @return */ def humpToUnderLine(str : String) : String = { var result = "" for(char <- str) { if(char.isUpper) { result += "_" + char } else { result += char } } result } def main(args: Array[String]): Unit = { println("hello world scala"); println(underlineToHump("hell_iii")) println(humpToUnderLine(underlineToHump("hell_iii"))) } }