我有两个arraylist filelist并且imgList彼此相关,例如与"e1.jpg"相关的"H1.txt".如何自动随机名单imgList根据随机化fileList?就像在Excel中一样,如果我们对某个列进行排序,另一列会自动跟随吗?
String [] file = {"H1.txt","H2.txt","H3.txt","M4.txt","M5.txt","M6.txt"};
ArrayList<String> fileList = new ArrayList<String>(Arrays.asList(file));
String [] img = {"e1.jpg","e2.jpg","e3.jpg","e4.jpg","e5.jpg","e6.jpg"};
ArrayList<String> imgList = new ArrayList<String>(Arrays.asList(img));
//randomized files
Collections.shuffle(fileList);
Run Code Online (Sandbox Code Playgroud)
随机化后的输出例如:
fileList = {"M4.txt","M6.txt","H3.txt","M5.txt","H2.txt","H1.txt"};
Run Code Online (Sandbox Code Playgroud)
预期输出:
imgList = {"e4.jpg","e6.jpg","e3.jpg","e5.jpg","e2.jpg","e1.jpg"};
Run Code Online (Sandbox Code Playgroud) 我试图使用此代码建议(http://www.daniweb.com/forums/thread23883.html#)将控制台输出写入txt文件但是我没有成功.怎么了?
try {
//create a buffered reader that connects to the console, we use it so we can read lines
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
//read a line from the console
String lineFromInput = in.readLine();
//create an print writer for writing to a file
PrintWriter out = new PrintWriter(new FileWriter("output.txt"));
//output to the file a line
out.println(lineFromInput);
//close the file (VERY IMPORTANT!)
out.close();
}
catch(IOException e1) {
System.out.println("Error during reading/writing");
}
Run Code Online (Sandbox Code Playgroud) 如何将2维数组展平int originalArray[][]为1维数组?
int a [] = {1,2,6,7,2};
int b [] = {2,44,55,2};
int c [] = {2,44,511,33};
int originalArray [][] = new int[][]{a,b,c};
Run Code Online (Sandbox Code Playgroud) 我想要绘制6个向量.我如何用不同的颜色(随机)制作每个图?使用下面的代码,图表限制为所有六个向量的一种颜色.
plot(x,y,'-rs','LineWidth',1,...
'MarkerEdgeColor','k',...
'MarkerFaceColor','g',...
'MarkerSize',5);
Run Code Online (Sandbox Code Playgroud) 我们如何在GridLayout中显示网格线?在Java?
JPanel panel = new JPanel(new GridLayout(10,10));
panel.setBorder(BorderFactory.createEmptyBorder(2,2,2,2));
for (int i =0; i<(10*10); i++){
panel.add(new JLabel("Label"));
}
Run Code Online (Sandbox Code Playgroud) JPanel pMeasure = new JPanel();
....
JLabel economy = new JLabel("Economy");
JLabel regularity = new JLabel("Regularity");
pMeasure.add(economy);
pMeasure.add(regularity);
...
Run Code Online (Sandbox Code Playgroud)
当我运行上面的代码时,我得到这个输出:
Economy Regularity
Run Code Online (Sandbox Code Playgroud)
如何获得此输出,每个JLabel在新行上启动?谢谢
Economy
Regularity
Run Code Online (Sandbox Code Playgroud)