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 9 of 9

Thread: Parallel vectors synchronize

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

    Default Parallel vectors synchronize

    Hello,
    in my code i have at some point 3 parallel vectors [float(i)<=>string1(i)<=>string2(i)]

    i wanted to eliminate equal float numbers of the 1st vector ,therefore i create a SET which works fine:
    Set unique = new LinkedHashSet();
              Iterator iter;
              for ( iter = unique.iterator(); iter.hasNext();) {
                     Object obj = iter.next();
                     System.out.println("/unique vector/ " + obj);}
    Im having difficulty at deleting the correspoding strings of the other 2 vectors,although it sounds pretty easy to do.
    i would appreciate any ideas!
    thnx very much a priori


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Parallel vectors synchronize

    How are you loading the Set from the Vector? If you did that in a loop you would have the index needed to access the other two Vectors.
    If you don't understand my answer, don't ignore it, ask a question.

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

    Default Re: Parallel vectors synchronize

    its loaded outside the loop ,and moving that control inside the loop would cause more problems

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Parallel vectors synchronize

    cause more problems
    How is that?
    If you don't understand my answer, don't ignore it, ask a question.

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

    Default Re: Parallel vectors synchronize

    inside the loop i find dynamically the values of float numbers and the correspodining values of string1 and string 2
    if i try to create the set inside the loop then the values are not correct(unless im missing something)

    PS:now that i think of it , its more convenient to find a way to eliminate duplicates
    a SET contains the unique values and not only the duplicates if im correct
    Last edited by speaker; May 18th, 2012 at 02:36 PM.

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Parallel vectors synchronize

    Inside the loop that is creating the Vectors, you could use the Set to tell you if the current float is already in the Set.
    If you don't understand my answer, don't ignore it, ask a question.

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

    Default Re: Parallel vectors synchronize

    i am trying that but i cant make it work. I have a loop inside a loop and that makes things worse

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

    Default Re: Parallel vectors synchronize

    Don't be scare of loops inside loops. It is a VERY common practice. I think I've gone further than 7 loops deep before.
    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/

  9. #9
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Parallel vectors synchronize

    i cant make it work
    Can you explain what problems you are having?
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Hello! parallel vectors nightmare
    By speaker in forum Collections and Generics
    Replies: 2
    Last Post: May 18th, 2012, 02:12 PM
  2. When to Synchronize Code
    By Bijaysadhok in forum Threads
    Replies: 12
    Last Post: March 16th, 2012, 09:28 AM
  3. Counting Matches in Parallel Arrays
    By dx8292 in forum Object Oriented Programming
    Replies: 3
    Last Post: February 1st, 2012, 09:45 AM
  4. Help with parallel array
    By kid20304 in forum Collections and Generics
    Replies: 3
    Last Post: December 6th, 2011, 05:41 PM
  5. parallel array newbie
    By NewAtJava in forum What's Wrong With My Code?
    Replies: 5
    Last Post: November 1st, 2011, 09:21 PM