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.


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

Results 1 to 3 of 3

Thread: Searching arrays

  1. #1
    Junior Member
    Join Date
    Sep 2013
    Thanked 0 Times in 0 Posts

    Default Searching arrays

    I need to find elements from an array that are unique.
    The program is supposed to identify the duplicate elements as they are being entered and not count them.
    For example: if I enter 10 then 20 then 15 then 10 then 20. The program is supposed to identify only the unique numbers in this case 15
    I tried to use a linear search method like the one below but this will only compare the elements against one key

    public class LinearSearch{
    public static in linearSearch(int[] list, int key){
    for (int i = 0; i < list.lenght; i++){
    if(key == list [i])
    return i;
    return -1:

  2. #2
    Grand Poobah
    Join Date
    Mar 2011
    My Mood
    Thanked 167 Times in 158 Posts

    Default Re: Searching arrays

    You only need to compare the elements against one key. By that I mean you pseudocode should be along the lines of

        enter value
        if value is not in array { // call a method that checks and returns a boolean
            enter value into array
    boolean method
        for each element in array
            if element equals new value
                return ....
        return ....
    Improving the world one idiot at a time!

  3. The Following User Says Thank You to Junky For This Useful Post:

    camaleonx13 (October 1st, 2013)

  4. #3
    Super Moderator
    Join Date
    Jun 2013
    So. Maryland, USA
    My Mood
    Thanked 698 Times in 680 Posts

    Default Re: Searching arrays

    Please read the Announcement at the top of the sub-Forums to learn how to post your code in code/formatting tags and how to ask questions that get attention and receive helpful answers.

Similar Threads

  1. [SOLVED] get value from database by searching
    By Light Mike in forum JDBC & Databases
    Replies: 4
    Last Post: August 23rd, 2012, 02:43 AM
  2. Searching
    By killer3p0 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: May 17th, 2012, 08:06 AM
  3. [SOLVED] Searching issues.
    By Saintroi in forum What's Wrong With My Code?
    Replies: 2
    Last Post: April 28th, 2012, 07:26 PM
  4. searching a string
    By dvsumosize in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 23rd, 2010, 01:31 AM
  5. Searching Data
    By kalees in forum JavaServer Pages: JSP & JSTL
    Replies: 3
    Last Post: October 2nd, 2009, 03:23 AM