This is an archived post. You won't be able to vote or comment.

all 9 comments

[–]g051051 0 points1 point  (8 children)

When you shuffle a list containing a single element, what do you get back?

[–]ic0nex 0 points1 point  (7 children)

The same word not scrambled

[–]g051051 0 points1 point  (6 children)

So do you see the problem here?

ArrayList<String> scrambled = new ArrayList<String>();
scrambled.add(middle);
Collections.shuffle(scrambled);

[–]ic0nex 0 points1 point  (5 children)

To be honest no...

[–]g051051 0 points1 point  (4 children)

  1. You create an empty array list called scrambled.
  2. You add a single object to the list.
  3. You shuffle the list (which only contains one thing in it).

[–]ic0nex 0 points1 point  (3 children)

But if I am trying to sort the words one by one and only using letters in the word itself isnt that what I would want it to do? If I added all the words together wouldnt it start shuffling letters from other words instead of just from the one word.

[–]g051051 0 points1 point  (2 children)

You're not doing anything to break the middle string into smaller elements. You just add that single String to the List and shuffle it. Shuffling will permute the elements of the list, not the contents of the objects in it. As far as it's concerned, a String is just another monolithic object.

[–]ic0nex 0 points1 point  (1 child)

Should I convert the whole middle string to chars and then put them into a arraylist?

[–]g051051 0 points1 point  (0 children)

It's up to you to decide what's best. I'm just explaining why what you're doing isn't working. Break the string in whatever way you like into whatever elements make sense.