1

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.

Dave_P
  • 174
  • 2
  • 16
  • sort is for sorting not for randomizing, it is the complete opposite of randomizing – oers Dec 15 '11 at 15:03

1 Answers1

3

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.

Mario Fusco
  • 13,548
  • 3
  • 28
  • 37
  • Thanks Mario, that actually was the chosen answer for me. As for sort... Can you not sort an item any way you want to? Ascending, Descending, by date modified... randomly? I dont consider them opposites, but I do understand how you guys would think so. Thanks for all of your help from here, and the email previous to that. Cant wait to learn more about lambdaj in the near future. – Dave_P Dec 20 '11 at 13:48