LambdaJ 专家...如何随机化输出

发布于 2024-12-21 08:09:52 字数 380 浏览 3 评论 0原文

我一直在尝试自学 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

总以为 2024-12-28 08:09:52

我是 lambdaj 的作者,但我不明白为什么你希望用它随机化一个项目列表。老实说,我也不明白为什么你认为排序方法(oers 已经指出排序与随机化相反)应该这样做。

无论如何,我想 Collections 类的 shuffle 静态方法应该可以满足您的需要:

Collections.shuffle(names)

我希望这会有所帮助。

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:

Collections.shuffle(names)

I hope this helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文