小编Spo*_*ngi的帖子

Java 8 Streams解析为Integer

是否存在使用流将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)

java java-8 java-stream

6
推荐指数
1
解决办法
4291
查看次数

Material UI 5.0 Typescript React 自定义主题

我在使用 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)

typescript reactjs material-ui

6
推荐指数
1
解决办法
4182
查看次数

Java 8 Consumer 按行拆分

有人可以告诉我应该如何使用消费者来达到相同的输出,因为这不起作用?

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 java-8

5
推荐指数
1
解决办法
1009
查看次数

Java限制长度整数

我是Java的新手,我需要一些帮助.

有人能告诉我如何在此代码中将限制长度设置为整数= 6.

例如

id = 124973 

public void setId(int id) {
    this.id = id;
}
Run Code Online (Sandbox Code Playgroud)

java validation integer

4
推荐指数
1
解决办法
4572
查看次数

Java 8 Streams取String线的总和

如何使用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 lambda java-8 java-stream

2
推荐指数
2
解决办法
2409
查看次数