Results 1 to 6 of 6
- 12-20-2011, 03:02 PM #1
Member
- Join Date
- Dec 2011
- Posts
- 4
- Rep Power
- 0
Sort a list alphabetically and split it into groups (From A to E, From F to J....)
Hi,
I have an arraylist which I have to sort in an alphebetical order then I have to split it into 5 sets
- set 1 containing list of words between A and E
- set 2 containing list of words between F and J
- set 3 containing list of words between K and O
- set 4 containing list of words between P and T
- set 5 containing list of words between U and Z
Also, there are some elements in the arraylist which start with a number, I have to have another set
- set 6 containing list of between 0 and 9
Can anyone help please???
Thanks in advance
- 12-20-2011, 03:07 PM #2
Re: Sort a list alphabetically and split it into groups (From A to E, From F to J....
What have you tried? Where are you stuck? How would you do this by hand, without a computer?
How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
- 12-20-2011, 03:35 PM #3
Member
- Join Date
- Dec 2011
- Posts
- 4
- Rep Power
- 0
Re: Sort a list alphabetically and split it into groups (From A to E, From F to J....
Thanks for your reply. I can sort the list alphabetically using the collection interface on List
ArrayList<String> ParamList = new ArrayList<String>();
Now what I want is a way to filter the list. I would like to create sublists of alphabet by spliting the 26 letters of the alphabet into 5 sublists
From A and E contains all strings starting with A, B, C, D or E
From F and J contains all strings starting with F, G, H, I or J
From K and O contains all strings starting with K, L, M, N or O
From P and T contains all strings starting with P, Q, R, S or T
From U and Z contains all strings starting with U, V, W, X, Y or Z
This is to allow easier searh, instead of displaying the whole list of data, I first want to filter in order to avoid displaying a long list.
- 12-20-2011, 03:48 PM #4
Member
- Join Date
- Dec 2011
- Posts
- 4
- Rep Power
- 0
Re: Sort a list alphabetically and split it into groups (From A to E, From F to J....
One way of doing this could be to declare 5 sublists and state that if for example:
a string starts with letter "A" then place it in list 1,
String starts with letter "G" then place it in list 2....
Or, we can create 26 lists, a list for each letter in the alphabet, then put its content if not empty in a new list
Thanks
- 12-20-2011, 04:22 PM #5
Member
- Join Date
- Dec 2011
- Posts
- 4
- Rep Power
- 0
Re: Sort a list alphabetically and split it into groups (From A to E, From F to J....
In a clearer way:
I have a list of strings some begin with a number (eg. 6Kv, 9Hv) and some begin with a letter from the alphabet (eg. Aa, Clapet, Joint...)
I want to filter the data and create 6 sublists
List1 : contains all strings beginning with a number sorted from 0 to 9
List2 : contains all strings beginning with A, B, C, D, E
List3 : contains all strings beginning with F, G, H, I, J
List4 : contains all strings beginning with K, L, M, N, O
List5 : contains all strings beginning with U, V, W, X, Y, Z
Please, HELP
- 12-21-2011, 03:39 AM #6
Re: Sort a list alphabetically and split it into groups (From A to E, From F to J....
Right, so this is simple. Create your 6 lists. Iterate through the main list (after it has been sorted). Use the String class' beginsWith() method or the charAt() to see what the string starts with. If it begins with A, B, C, D or E, put it in list one. Repeat for each remaining item into its corresponding bucket. A loop and a switch statement should do this easily.
Similar Threads
-
need help to sort a list
By gretaks in forum New To JavaReplies: 13Last Post: 11-02-2011, 10:07 PM -
Sort by Word frequency and alphabetically
By darpan12 in forum New To JavaReplies: 3Last Post: 01-06-2011, 06:26 PM -
Arraylist problem Sort Date , alphabetically
By ob3lix in forum New To JavaReplies: 1Last Post: 11-26-2010, 03:55 PM -
how to sort jtable with row groups
By mordjah in forum AWT / SwingReplies: 0Last Post: 10-25-2010, 05:23 PM -
How to sort a list using Bubble sort algorithm
By Java Tip in forum AlgorithmsReplies: 3Last Post: 04-29-2008, 08:04 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks