Parsing Strings Delimited by Double Spaces in a Database Field

From a single field of a database, I need to read and parse multiple strings delimited by 2 spaces. Each possible entry from this field is represented in a JList, so I'm wanting the JList entries that are present in the database field to be highlighted. An example entry in the database might be:

This is string1this is string2this is string3

So I'd want three different selections highlighted in my JList: "This is string1" "this is string2" and "this is string3"

Can anyone suggest a good way to do this? I've been playing around with the Reader class and Scanner class, but can't seem to get the working logic down on paper. Thanks for the help!

[745 byte] By [ScottS.a] at [2007-11-26 14:29:24]
# 1
I'm assuming that the data is in a single string. Use String.split and specify the regular expression that delineates the tokens you want - that is, the double spaces - " "
ChuckBinga at 2007-7-8 2:23:45 > top of Java-index,Core,Core APIs...
# 2
Small correctionthe regex for double spaces should beeither "\\s\\s" or "\\s{2}"
LRMKa at 2007-7-8 2:23:45 > top of Java-index,Core,Core APIs...
# 3
An even smaller correction ;)two quoted space characters work just fine. (But I was saying "specify the regular expression that delineates the tokens you want ", so any ot these work.)
ChuckBinga at 2007-7-8 2:23:45 > top of Java-index,Core,Core APIs...
# 4

I think this is working and I now have a String[] of values to work with. What I'm needing to do now is to highlight each value from the String[] on a pre-populated JList. I tried JList.setSelectedIndex(), but that won't work with multiple strings. Any ideas? Below is what I tried:

String[] classes = MainMenu.rs.getString(6).trim().split(" ");

for(int i = 0; i < classes.length; i++)

{

jList1.setSelectedValue((Object)classes[i]);

}

Only the last element of the array is getting highlighted. I checked the contents of the array, and there are multiple entries. How can I get all of the entries highlighted?

Message was edited by:

ScottS.

ScottS.a at 2007-7-8 2:23:45 > top of Java-index,Core,Core APIs...
# 5

Probably too late but can help to someone else. This should do the job:

String[] classes = MainMenu.rs.getString(6).trim().split(" ");

int[] indices = new int[classes.length];

for (int i = 0; i < classes.length; i++) {

indices[i] = i;

}

jList1.setListData(classes);

jList1.setSelectedIndices(indices);

Yaakopa at 2007-7-8 2:23:45 > top of Java-index,Core,Core APIs...