File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes TreeSet contains Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Make it so: Java DB Connections & Transactions this week in the JDBC forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "TreeSet contains "something like this"" Watch "TreeSet contains "something like this"" New topic

TreeSet contains "something like this"

Luke Shannon
Ranch Hand

Joined: Sep 30, 2004
Posts: 239
I have the following code:

Basically if kFields, cFields contain field I enter the if condition.

My boss wants me to add a regular expression to kField. Example:

kField would contain among other things: TEXT*

The desired effect is in the if statement above, if field contains TEXT1, TEXT2...TEXT<anything> I will enter the if condition. The star acts as a wildcard.

I was thinking about how to do this.

I could step through the TreeSet and compare each value to the value contained in Field using regex. This seems a little expensive.

Is there any easier way? Perhaps a better collection for this? Maybe I should sub class TreeSet and make my own contains that handles regex? This is part of a method that is becoming a performance concern for me, so I would like to be as effecient as possible.

Any suggestions,


[ March 18, 2005: Message edited by: Luke Shannon ]

Luke Shannon
Ranch Hand

Joined: Sep 30, 2004
Posts: 239
Here is the solution I ended up with. If anyone can think of a better way please let me know.


I agree. Here's the link:
subject: TreeSet contains "something like this"
It's not a secret anymore!