我试图使用lambda表达式将String数组转换为Integer数组.
我在下面提供了我的代码,以及到目前为止我所尝试的内容的简要说明:
String [] inputData = userInput.split("\\s+");
Integer [] toSort = new Integer [] {};
try {
toSort = Arrays.asList(inputData).stream().mapToInt(Integer::parseInt).toArray();
}catch(NumberFormatException e) {
System.out.println("Error. Invalid input!\n" + e.getMessage());
}
Run Code Online (Sandbox Code Playgroud)
我上面的lamba表达式是一个映射到int数组的表达式,这不是我想要的,在编译此代码时我收到以下错误消息:
BubbleSort.java:13: error: incompatible types: int[] cannot be converted to Integer[]
toSort = Arrays.asList(inputData).stream().mapToInt(Integer::parseIn
t).toArray();
^
1 error
Run Code Online (Sandbox Code Playgroud)
是否有一种简单的方法允许我使用lambdas或其他方法从String数组到Integer数组?
我在下面有2个枚举.
CONFIG_URLS.BASE_URL
CONFIG_URLS.URL1
Run Code Online (Sandbox Code Playgroud)
这些枚举中的每一个都指向一个字符串.
我想通过连接BASE_URL和创建一个字符串变量URL1.应该是快捷的代码.有人可以帮忙吗?非常感谢