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 and displaying results in a multi-dimensional array.

  1. #1
    Junior Member
    Join Date
    Feb 2012
    Thanked 0 Times in 0 Posts

    Default Searching and displaying results in a multi-dimensional array.

    I'm working on a two column array search utility, but I'm stuck on a couple of matters.

    1. I want to insure that the utility only searches the first column of the array and ignores the second.
    2. When it does find the word in the first column, I want it to display the second column on line 109.

    I've got the majority of it written, but like I said, I'm stuck. Help is always appreciated.

        import java.awt.*;  
        import javax.swing.*;  
        class SearchJavaGlossary  
          private static String[][] javaGlossarySearch =  {  
            {"absolute path","a complete file path that does not require any other information to locate a file on a system."},  
            {"abstract class","a class from which you cannot create any concrete objects, but from which you can inherit. Abstract classes usually have one or more empty abstract methods. Contrast with concrete classes."},  
            {"abstract data type","a type whose implementation is hidden and accessed through its public methods."},  
            {"abstract method","a method declared with the keyword abstract; it is a method with no body that must be implemented in a subclass."},  
            {"Abstraction","the programming feature that allows you to use a method name to encapsulate a series of statements."},  
            {"Accelerator","a key combination that causes a menu item to be chosen, whether or not the menu item is visible."},  
            {"access modifier","an access specifier."},  
            {"access specifier","defines the circumstances under which a class can be accessed and the other classes that have the right to use a class."},  
            {"accessor methods","methods that return information about an object."},  
            {"Accumulating","the process of repeatedly increasing a value by some amount to produce a total."},  
            {"action key","a keyboard key that does not generate a character."},  
            {"actionPerformed(ActionEvent e) method","a method that defines the actions that occur in response to an event."},  
            {"actual parameters","the arguments in a method call. Contrast with formal parameters."},  
            {"acyclic gradient","a fill pattern in which a color shift occurs once between two points."},  
            {"adapter class","a class that implements all the methods in an interface, providing an empty body for each method."},  
            {"add and assign operator","an operator that alters the value of the operand on the left by adding the operand on the right to it; it is composed of a plus sign and an equal sign ( += )."},  
            {"add() method", "a method that adds components to a container."},  
            {"addActionListener() method","a method that tells a class to expect ActionEvents."},  
            {"addPoint() method","a method that adds points to a Polygon object."},  
            {"ad-hoc polymorphism","polymorphism that occurs when a single method name can be used with a variety of data types because various implementations exist; it is another name for method overloading."},  
            {"aggregation","a type of composition in which a class contains one or more members of another class that would continue to exist without the object that contains them."},  
            {"Allman style","the indent style in which curly braces are aligned and each occupies its own line; it is named for Eric Allman, a programmer who popularized the style. Contrast with K & R style."},  
            {"ambiguous","describes a situation in which the compiler cannot determine which method to use."},  
            {"anonymous classes","nested, local classes that have no identifier."},  
            {"anonymous object","an unnamed object."},  
            {"append() method","a StringBuilder class method that lets you add characters to the end of a StringBuilder object."},  
            {"applet","a Java program that is called from within another application, frequently a Web page."},  
            {"Applet Viewer","a program that comes with the JDK that allows you to view applets without using a Web browser."},  
            {"appletviewer command","a command that allows you to view an applet in a viewing program that comes with the JDK."},  
            {"application","a stand-alone, executable program."},  
            {"application files","files that store software instructions. See also program files."},  
            {"application-triggered painting","painting operations that occur when the internal state of a component has changed.Contrast with system-triggered painting."},  
            {"arc", "a portion of a circle."},  
            {"architecturally neutral","describes the feature of Java that allows a program to run on any platform."},  
            {"argument index","in a printf() statement, an integer that indicates the position of an argument in the argument list."},  
            {"arguments","data items sent to methods in a method call."},  
            {"arithmetic operators","operators used to perform calculations with values."},  
            {"array","a named list of data items that all have the same type."},  
            {"ArrayList class","a Java class that provides a dynamically resizable container that stores lists of objects."},  
            {"Arrays class","a built-in Java class that contains many useful methods for manipulating arrays, such as methods to search, fill, compare, and sort arrays."},  
            {"ascending","describes the order from lowest value to highest."},  
            {"ascent","one of three measures of a Fontís height; it is the height of an uppercase character from a baseline to the top of the character. See also leading and descent."},  
            {"ASCII","an acronym for American Standard Code for Information Interchange, a character set widely used to represent computer data."},  
            {"assert statement","a statement that creates an assertion."},  
            {"assertion","a Java language feature that can help you detect logic errors and debug a program."},  
            {"assignment","the act of providing a value for a variable."},  
            {"assignment operator","the equal sign ( = ); any value to the right of the equal sign is assigned to the variable on the left of the equal sign."},  
            {"associativity","describes the order in which operands are used with operators."},  
            {"at run time","describes the period of time during which a program executes."},  
            {"attributes","the characteristics that define an object as part of a class."} };  
          public static void main(String[] args)  
          } //end main()  
          public static void searchGloss()  
            boolean wordWasFound = false;  
            boolean validEntry = false;  
            String message = "";  
            while(validEntry == false)  
              String searchWord = JOptionPane.showInputDialog(  
                                        "Enter the word you"  
                                        + " would like to search in the Java reserved "  
                                        + "keyword list","Java Keyword search",  
              if(searchWord == null) return; //sends user back to option screen  
              else if(searchWord.equals(""))  
                                "Please type a word before pressing the enter key or "  
                                + "clicking OK.",  
                    "Search results",  
                validEntry = true;  
                for(int x = 0, y = javaGlossarySearch.length; x < y; x++)  
                  for(int xx = 0, yy = javaGlossarySearch[x].length; xx < yy; xx++)  
                      wordWasFound = true;  
                    if(wordWasFound) break;  
                    message = ": " // change this for the definition  
                  message = " was not found!";  
                                "'" + searchWord + "'" + message,  
                                "Search results",  
            }//end while  
          }// end searchJavaGlossary()  
        }//end class

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Eastern Florida
    Thanked 2,274 Times in 2,245 Posts

    Default Re: Searching and displaying results in a multi-dimensional array.

    I'm stuck
    Please explain where you are stuck.

    I want to insure that the utility only searches the first column of the array
    Do you know how to code a reference to the first column of a 2 dim array?

    To see what your code is doing add a println that prints out this value: javaGlossarySearch[x][xx]
    just before the line where you compare it to searchWord. You need to see what the program is doing.

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

    wfalcon2012 (February 19th, 2012)

  4. #3
    Junior Member
    Join Date
    Feb 2012
    Thanked 0 Times in 0 Posts

    Default Re: Searching and displaying results in a multi-dimensional array.

    I just got it all straightened out. Thanks.

Similar Threads

  1. Your input with written code (Sorting and searching within array)
    By GalBenH in forum What's Wrong With My Code?
    Replies: 9
    Last Post: January 11th, 2012, 08:19 AM
  2. How can I create a jigsaw puzzle with Array multi-dimensional?
    By ivan8 in forum What's Wrong With My Code?
    Replies: 15
    Last Post: December 4th, 2011, 07:13 PM
  3. Replies: 3
    Last Post: October 26th, 2011, 03:37 PM
  4. Searching and printing string results from an Arraylist. Having difficulty.
    By Espressoul in forum Loops & Control Statements
    Replies: 1
    Last Post: February 25th, 2010, 07:32 PM
  5. Multi Dimensional Array help NEEDED URGENT
    By bonjovi4u in forum Loops & Control Statements
    Replies: 5
    Last Post: February 12th, 2010, 11:44 PM