Can Java vector class return incorrect results when using contains.

Joined
Mar 1, 2011
Messages
2
Reaction score
0
Hi Everyone I've tried searching through the forum and did notice a lot about the fact that the vector classes contains method uses the concept of object.equals.

Now in my case my vector contains a single item and the vector is one of strings i.e. nothing fancy not trying to store arrays in the vector


The issue I am having is that for some reason when using the contains method it is returning True when it should be returning false.

snippets of the code
Code:
        // Vector to hold the list of ClassName's that should be evaluated for Integration handling
        Vector<String> classNameList = new Vector<String>();

// IntegrationsConfig.conf contains one line item
// [B]MOMTrap[/B],MomTrapSendspool,Create|Acknowledged|Delete|ClearOnAcknowledge


// Create a scanner to iterate through the FilterExceptions.conf file
FileInputStream istream = new FileInputStream("IntegrationsConfig.conf");
Scanner ourScanner = new Scanner(istream).useDelimiter("\n");

// Read the spool file to fill in the rest of the fields
while(ourScanner.hasNext())
{
        String line = ourScanner.next();

        // Split the line on commas for the ClassName,SpoolDir,Actions settings

        if ((!(Pattern.matches("^#.*", line))) &&
                (!(line.equals(""))))
        {
                String[] integrationConfig = line.split(",");
                // Add the ClassName configured into the vector list classNameList
                //classNameList.addElement(integrationConfig[0]);
                classNameList.addElement(integrationConfig[0].toString());

        }
}


// This is where the 'fault' happens
// Previously didn't have the isEmpty condition but the fault was present before that

// className is just a String.
if ((!(classNameList.isEmpty())) && (classNameList.contains(className)));
{
.......
.....
}



so when className is say SCOMTrap it is being matched by the contains when the vector only contains MOMTrap


Not sure if should switch this to a List item instead? My code has about 5 other String Vectors all behaving as they should.



Funny enough something else happened when I did this section of development, previously the pattern match to prevent comment lines from being read was just


Pattern.matches("^#", line) which was working on reading another config file.suddenly stopped working and I changed it to
Pattern.matches("^#.*", line) for the new config file


Thanks for any help.

I'm very much a relative newbie to java itself ... perl developer :oops:
 
Last edited:
Joined
Mar 1, 2011
Messages
2
Reaction score
0
My Bad found the problem


Code:
// the ; at the end of the if statement
if ((!(classNameList.isEmpty())) && (classNameList.contains(className)));
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,709
Latest member
AustinMudi

Latest Threads

Top