Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: EASY [comparing two vectors of strings]

  1. #1
    Junior Member
    Join Date
    Mar 2012
    Posts
    26
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default EASY [comparing two vectors of strings]

    Hello,
    i have two vectors containing strings.These two vectors they dont have the same length.
    I need to compare the strings between vector A and vector B ,and find sets of similar strings.
    At the end i need to delete the similar strings form vector A.

    Thank you for your help a priori.


  2. #2
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,676
    Thanks
    25
    Thanked 329 Times in 305 Posts

    Default Re: EASY [comparing two vectors of strings]

    You can check if a Vector of Strings contains a specified String. To do that, you envoke the Vector.contains(String) method (which returns a boolean). You would just need to loop through Vector A and envoke the contains() method on Vector B for each of Vector A's indexes.

    As for removing the similar Strings, you can loop through Vector A and use the Vector.remove(Object) method, and send it the Strings that you know are similar between the two Vectors. Or, if you were particularly lazy, you could call A.removeAll(B);. I believe that call *should* remove all the elements from Vector A that Vector B also has.
    NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:

    When asking for help, please follow these guidelines to receive better and more prompt help:
    1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
    2. Give full details of errors and provide us with as much information about the situation as possible.
    3. Give us an example of what the output should look like when done correctly.

    Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/

  3. #3
    Junior Member
    Join Date
    Mar 2012
    Posts
    26
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: EASY [comparing two vectors of strings]

    I think this answer will be helpful. I will try to work it out now.
    Below there is the output of the two vectors A and B as an example.
    i hope its helpful
    ----------(suitableForProcess>=1,hasTypeProfile>=1,hasTypicalConsumption>=1,hasLoadProfile>=1,¥hasTypicalConsumption.(Watt>=30,Watt<=30),¥hasTypeProfile.(MediumShift,Shiftable,TypeProfile,Profile),¥hasLoadProfile.(ConstantLoad,LoadProfile,Profile),¥suitableForProcess.(WatchingPhoto,MentalProcess,Process,EnvironmentTemperatureRegulation,Functionality,NormalSafetyLevel,SafetyLevelRegulation,MediumSecurityLevel,SecurityLevelRegulation,SoftLightLevel,LightLevelRegulation,PlayPhoto,!HighSecurityLevel,!LowSecurityLevel,!BrightLightLevel,!LowLightLevel,!NoLight,!NormalLightLevel))
    ----------(suitableForProcess>=1,isSuggestedForWeatherCondition>=1,isSuggestedForOutdoorLuminosity>=1,isSuggestedForTemperature>=1,¥isSuggestedForOutdoorLuminosity.(HighLuminosity,OutdoorLuminosity,Weather,!LowLuminosity,!MediumLuminosity),¥isSuggestedForWeatherCondition.(Sunny,WeatherCondition,Weather,!Cloudy,!PartlyCloudy,!Rain),¥isSuggestedForTemperature.(Heat,Temperature,PhysicalStatus,Characteristic,!Cold,!Normal,!Refreshing,!Warmth),¥suitableForProcess.(BodyProcess,Process,EnvironmentTemperatureRegulation,Functionality,Cook,KitchenWork,KitchenLight,LightLevelRegulation,VentilationFunctionality,Eating))

  4. #4
    Junior Member
    Join Date
    May 2012
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Sorry misread... As started before iterate through one of the vectors and compare against the contents of the other.

    Michael.
    Last edited by MES Enterprises LLC; May 14th, 2012 at 05:20 PM.

  5. #5
    Super Moderator Sean4u's Avatar
    Join Date
    Jul 2011
    Location
    Tavistock, UK
    Posts
    637
    Thanks
    5
    Thanked 103 Times in 93 Posts

    Default Re: EASY [comparing two vectors of strings]

    Do you mean java.util.Vector when you say 'vector', or something else? Your problem sounds like it would be natural to solve it with java.util.Set:
    The Set Interface (The Java™ Tutorials > Collections > Interfaces)
    The method names will be familiar from aussiemcgr's post, but I suspect the implementations / performance (because java.util.Vector implements List) may vary greatly.

  6. #6
    Junior Member
    Join Date
    Mar 2012
    Posts
    26
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: EASY [comparing two vectors of strings]

    im sorry
    noob mistake
    i have two vectors containing ITEMS .At the end of the loops of the vectors i get 2 Items and i have to compare them .
    they look like this:

    ITEM A:---------->suitableForProcess>=1,hasTypeProfile>=1,(Watt>=30 ,Watt<=30),¥hasTypeProfile.(MediumShift,Shiftable, TypeProfile,Profile),¥hasLoadProfile.(ConstantLoad ,LoadProfile,Profile),¥suitableForProcess.(Watchin gPhoto,!NoLight,!NormalLightLevel)

    ITEM B:--------->suitableForProcess>=1,isSuggestedForWeatherCondit ion>=1,¥isSuggestedForOutdoorLuminosity.(HighLumin osity,OutdoorLuminosity,Weather,!LowLuminosity,!Me diumLuminosity),¥isSuggestedForTemperature.(Heat,T emperature,PhysicalStatus,Characteristic,!Cold,!No rmal,!Refreshing,!Warmth)

    After comparing those items,ill have to eliminate from Item A equal descriptions:
    in this example suitableForProcess>=1 must be eliminated

    **Note:those are semantic descriptions

Similar Threads

  1. [SOLVED] Comparing Date Strings
    By wdh in forum What's Wrong With My Code?
    Replies: 3
    Last Post: April 26th, 2012, 03:28 AM
  2. Comparing a character to an array of strings
    By Hashmeer169 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: December 4th, 2011, 07:55 PM
  3. user input strings to vectors
    By vudoo in forum What's Wrong With My Code?
    Replies: 9
    Last Post: February 7th, 2011, 10:30 PM
  4. Comparing Strings?
    By wandertheverse in forum What's Wrong With My Code?
    Replies: 4
    Last Post: February 4th, 2011, 10:32 PM
  5. Comparing Strings only using the .length() method - possible?
    By Ryker in forum What's Wrong With My Code?
    Replies: 6
    Last Post: October 16th, 2010, 05:52 PM