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

Thread: Comparing similar elements in an array

  1. #1
    Junior Member
    Join Date
    Sep 2011
    Posts
    8
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Comparing similar elements in an array

    Dear All-

    While working on a programming in (Basic Language) which we use for translating our customers data into ERP system, I came across an issue where I need to write the data to SQL. I am done with that but here is the problem.

    There is possibility that customer sends same part in different lines and I want to catch that instance of same part and write the occurrence of how many times the part is coming.

    Since there is a lot of limitation in basic programming language I am not able to catch the instances of how many times
    the part shows up or may be i dont know advance basic programming (since i am a novice). However the software allows use of Java programming inside basic programming.

    I wanted to know how to implement the solution for the above problem in Java.

    I have defined an array in Basic of n rows and 14 columns. These 14 columns refer to 14 columns
    of SQL table. The array is given below to be specific.
    Details[1000][14]
    One of the columns (column 7) is a counter which counts for the repetition of the occurrence of same part.
    so for example in the above scenario


    For Example: The Array will have.
    Line PartNo other col Counter
    Line1 PartA …. 1
    Line2 PartB …. 1
    Line14 PartC …. 1
    Line9 PartA …. 2 (repeated second time so 2)
    Line5 PartD … 1
    Line70 PartB …. 2 (repeated second time so 2)
    Line90 PartA …. 3 (repeated second time so 3)

    Hope I was able to explain the problem. My ask is to how to capture the repeated occurrences and write the n number of occurrences into Column named counter.
    Please note that the Line Column is not in serial order.

    Thanks for your help.
    FJ


  2. #2
    Junior Member
    Join Date
    Sep 2011
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Comparing similar elements in an array

    Hey!
    Did you try using the String1.compareTo(String2) while using for loop to check all the occurences.
    Hope this helps
    Cheers

  3. #3
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,147
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Comparing similar elements in an array

    Look at all the String class methods. There are several that will be useful.

Similar Threads

  1. [SOLVED] ArrayList object's elements confusing??? doesnt replace the elements? set() method?
    By chronoz13 in forum What's Wrong With My Code?
    Replies: 10
    Last Post: June 21st, 2011, 01:20 PM
  2. Comparing elements of an arrayList with an array?
    By DudeJericho in forum Collections and Generics
    Replies: 2
    Last Post: April 21st, 2011, 12:39 PM
  3. URGENT!!!! help with array element comparing
    By Neo in forum Java Theory & Questions
    Replies: 3
    Last Post: March 3rd, 2011, 08:52 AM
  4. Adding array elements inside a loop
    By Scotty in forum What's Wrong With My Code?
    Replies: 3
    Last Post: November 28th, 2010, 09:48 PM
  5. Method Adding elements to an array with certain restrictions
    By Newoor in forum Collections and Generics
    Replies: 1
    Last Post: December 13th, 2009, 11:13 AM