如何将以下代码转换为java8中的lambda ???
List<List<String>> my2dList = new ArrayList<List<String>>();
int counter = 0;
for (int i = 0; i < 5; i++) {
my2dList.add(new ArrayList<String>());
for (int j = 0; j < 10; j++) {
System.out.println("Counter: " +counter);
my2dList.get(i).add(new String(""+counter));
counter++;
}
}
Run Code Online (Sandbox Code Playgroud)
预期结果:
[[0,1,2,3,4,5,6,7,8,9],[10,11,12,13,14,15,16,17,18,19],[20,21, 22,23,24,25,26,27,28,29],[30,31,32,33,34,35,36,37,38,39],[40,41,42,43,44, 45,46,47,48,49]]
我正在尝试编辑txt文件中的第一行,但由于某种原因,它将用空格字符替换下一行...
int main()
{
FILE *myFile;
myFile = fopen("test.txt", "r+");
fprintf(myFile, "Hello\n");
fclose(myFile);
}
Run Code Online (Sandbox Code Playgroud)
运行代码前的txt文件:
i
like
this
Run Code Online (Sandbox Code Playgroud)
运行代码后的txt文件:
Hello
this
Run Code Online (Sandbox Code Playgroud)