我想将字符串转换为整数数组。 所以基本上我有一个用空格分隔的整数字符串,例如:“ 10 2 3 100” 我正在尝试将其转换为整数数组。我搜索的所有答案都将其转换为int数组。当然,我可以将其转换为int数组,然后将int数组转换为Integer数组。
const loadFile = () => {
//CORS URL
let corsURL = 'https://cors-anywhere.herokuapp.com/';
//My File URL
let myURL = 'https://your_url.com/file.json';
fetch(corsURL + myURL, { mode: 'no-cors'})
.then(response => response.json())
.then(content => {
console.log(content);
})
}
loadFile()
你们能告诉我是否有更短的方法吗? (像一行一样) 谢谢!
答案 0 :(得分:5)
您仍然希望使用filter
类型(特别是splice
),而不是IntStream
,因此应该调用Stream
而不是Stream<Integer>
。然后要将生成的mapToInt
转换为数组,请调用map
:
Stream<Integer>