LambdaJ 专家...如何随机化输出
我一直在尝试自学 Lambdaj,它似乎不想随机化我的字符串数组。我是否应该将字符串添加到列表中以便能够使用 Lambdaj 处理集合。我想做的就是获取字符串集合并使用 LambdaJ 以随机顺序打印它们。
String[] name = {"Me", "you", "them", "us", "Him", "Mr.T"};
String[] randomNames = sort(name, on(Random.class));
或者...
String[] randomNames = sort(name, on(String.class).???);
不知道该怎么办。 LambdaJ 上没有太多帮助。
I have been trying to teach myself Lambdaj and it doesn't seem to want to randomize my string array. Should I add the strings to a List to be able to work with the collection with Lambdaj. All I want to do is take a collection of strings and print them in random order using LambdaJ.
String[] name = {"Me", "you", "them", "us", "Him", "Mr.T"};
String[] randomNames = sort(name, on(Random.class));
or...
String[] randomNames = sort(name, on(String.class).???);
Not a clue what to do with this. There is not a whole lot of help out there on LambdaJ.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我是 lambdaj 的作者,但我不明白为什么你希望用它随机化一个项目列表。老实说,我也不明白为什么你认为排序方法(oers 已经指出排序与随机化相反)应该这样做。
无论如何,我想 Collections 类的 shuffle 静态方法应该可以满足您的需要:
我希望这会有所帮助。
I am the author of lambdaj, but I don't get why you expect to randomize a list of items with it. And to be honest I also don't understand why you think the sort method (oers already pointed out that sorting is the opposite of randomizing) should do that.
Anyway I guess the shuffle static method of the Collections class should do what you need:
I hope this helps.