我有幾個文件,我把它放在數組中。 我洗牌的文件,以便它可以隨機順序顯示。 如何知道數組索引0實際上是image1.txt或image2.txt或image3.txt? 提前致謝。
String[] a = {"image1.txt","image2.txt","image3.txt"};
List files = Arrays.asList(a);
Collections.shuffle(files);
我有幾個文件,我把它放在數組中。 我洗牌的文件,以便它可以隨機順序顯示。 如何知道數組索引0實際上是image1.txt或image2.txt或image3.txt? 提前致謝。
String[] a = {"image1.txt","image2.txt","image3.txt"};
List files = Arrays.asList(a);
Collections.shuffle(files);
我不確定你想要做什麽。
要訪問混洗列表的第一個元素,請使用 files.get(0)
。
如果你想知道每個元素的消失,我建議你采取另一種方法。創建一個從 0
到
a.length() - 1
的整數列表,並對該列表進行隨機播放。然後手動將數組
a
置換為新集合。