如何以相同的方式随机化两个ArrayLists?
我有两个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 filesCollections.shuffle(fileList);
随机化后的输出例如:
fileList = {"M4.txt","M6.txt","H3.txt","M5.txt","H2.txt","H1.txt"};
预期输出:
imgList = {"e4.jpg","e6.jpg","e3.jpg","e5.jpg","e2.jpg","e1.jpg"};
慕田峪9158850
largeQ
相关分类