是否存在使用流将String解析为Integer的更好方法:
String line = "1 2 3 4 5";
List<Integer> elements = Arrays.stream(line.split(" ")).mapToInt(x -> Integer.parseInt(x))
.boxed().collect(Collectors.toList());
Run Code Online (Sandbox Code Playgroud) 我在使用 TypeScript 在 Material UI 5.0 中自定义主题时遇到问题。
主题.ts
import { createTheme } from '@mui/material';
declare module '@mui/material/styles' {
interface Theme {
custom: {
buttonWidth: string;
};
}
interface ThemeOptions {
custom: {
buttonWidth: string;
};
}
}
export const theme = createTheme({
palette: {
primary: {
main: '#00F',
},
},
typography: {
body1: {
fontFamily: 'Comic Sans',
},
},
custom: {
buttonWidth: '200px',
},
});
export const CustomTheme= typeof theme;
Run Code Online (Sandbox Code Playgroud)
但是当我尝试使用它时,它不起作用
// CustomTheme imported
<Button sx={{ width: (theme: CustomTheme) => …Run Code Online (Sandbox Code Playgroud) 有人可以告诉我应该如何使用消费者来达到相同的输出,因为这不起作用?
String names = "John Alex Peter";
String[] namesSplitted = names.split(" ");
for (String s : namesSplitted) {
System.out.println(s);
}
Consumer<String> cons = x -> System.out.println(x.split(" "));
cons.accept(names);
Run Code Online (Sandbox Code Playgroud) 我是Java的新手,我需要一些帮助.
有人能告诉我如何在此代码中将限制长度设置为整数= 6.
例如
id = 124973
public void setId(int id) {
this.id = id;
}
Run Code Online (Sandbox Code Playgroud) 如何使用Stream找到此行中所有整数的总和?
String line = "Test 15 lqlq 35 bad 99999 guess 34";
List<String> lineSplitted = Arrays.stream(line.split(" ")).collect(Collectors.toList());
int result = 0;
try {
result = lineSplitted.stream().filter(s -> Integer.parseInt(s)).sum();
}
catch (Exception e) {
}
System.out.println(result);
Run Code Online (Sandbox Code Playgroud) java ×4
java-8 ×3
java-stream ×2
integer ×1
lambda ×1
material-ui ×1
reactjs ×1
typescript ×1
validation ×1