Question

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.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top