• Post Reply Bookmark Topic Watch Topic
  • New Topic

distribute tokens (cards)..  RSS feed

 
Jenny Calderon
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi... i'm new to java...

I have a string input like this --

String input = "D-K,D-Q,D-J,D-10,D-9,D-8,D-7,D-6,D-5,D-4,D-3,D-2,D-1";

I'm done tokenizing the string.

and i have to make an output like this..



list 1: D-K

list 2: D-Q, D-9

list 3: D-J, D-8, D-6

list 4: D-10, D-7, D-5, D-4



excess: D-3, D-2, D-1

please help me with the code... thanks!



 
Campbell Ritchie
Marshal
Posts: 56578
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why on earth do you want a 7-element array of Lists?
 
Jenny Calderon
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i just put 7 as a value to eliminate errors...
 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You know how to use ArrayList but still didn't think of a List<List<String>>? In other words, but your ArrayList in another List.
 
Campbell Ritchie
Marshal
Posts: 56578
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't go guessing values, producing a 7 out of thin air confuses the reader. It should readYou realise that creating an array of Lists precludes you from giving the Lists an actual type parameter (generics) and loses you the type-safety of generics? That is why Rob's suggestion is so much better.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!