Win a copy of Java Persistence with Spring Data and Hibernate this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Tim Cooke
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Jeanne Boyarsky
Saloon Keepers:
  • Stephan van Hulst
  • Carey Brown
  • Tim Holloway
  • Piet Souris
Bartenders:

Searching and displaying results in a multi-dimensional array.

 
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.


 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not a GUI problem. Moving to Beginning Java.

edit Also breaking some extra long code lines that are disturbing the page formatting
 
Saloon Keeper
Posts: 14792
333
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey there, Scotty. You didn't exactly specify what you're stuck on. Please TellTheDetails.

Anyway, have you considered using a Map<String, String> for this problem? It's perfect, it will solve most of your problems.
 
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I answered this yesterday:

Scotty Steven wrote: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.



What problem are you having with that? Just look in arr[x][0], and not in arr[x][1].

2. When it does find the word in the first column, I want it to display the second column on line 109.



So display arr[x][1].


And the OP even replied and thanked me.

Was this a double post? Or do we lose replies when moving a thread?
 
Scotty Steven
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Double post. I accidentaly posted in the Swing group. I realized it later, and reposted in beginners, which is were @Jeff Verdegan gave me the help needed. I marked this post (and the other) as soled last night, but doing so seems to have no effect.
 
Bartender
Posts: 3225
34
IntelliJ IDE Oracle Spring Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jeff Verdegan wrote:
And the OP even replied and thanked me.

Was this a double post? Or do we lose replies when moving a thread?



Double post. I chose to lock the other.
 
Scotty Steven
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Lock this one too. It's answered and done!
 
Marshal
Posts: 77539
372
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
We don’t close threadsd as a routine. I don’t think you have finished. There is a far better solution using a Map<String, String>
Also, to become pedantic, you don’t have a multi-dimensional array. You have an array of arrays. Which is, by the way, better than a 2D array.
 
Scotty Steven
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't know anything about Map<String, String>, but after getting the answer I was looking for last night, I formatted over 700 lines into an array, which seems to be working. I don't want to reformat the information again, as that took over 6 hours to do. I'm in if it uses the same format as an array, I'd consider it.
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Scotty Steven wrote:I don't know anything about Map<String, String>, but after getting the answer I was looking for last night, I formatted over 700 lines into an array, which seems to be working. I don't want to reformat the information again, as that took over 6 hours to do. I'm in if it uses the same format as an array, I'd consider it.



There's no good reason for putting all that in your Java code in the first place. It should go into a file that your code reads. Regardless of where it is though, if you're using a decent editor with regex replace capabilities, it will be trivial to change it from one to the other. Of course, if it's in a separate file as it should be, then the data format wouldn't change anyway; you'd just change a few lines of code at the point where you're reading and storing it.

(And to be honest, I don't think a String[][] OR a Map<String, String> is appropriate here. It looks like you have a glossary, so I'd defined a class named GlossaryEntry or Term or something appropriate to your intended design and use. That class would have as member variables the term and its definition. Then for lookups, I'd use use a Map<String, GlossaryEntry>.
 
Scotty Steven
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I just set it up with a main method for testing purposes only. It is part of a larger program, and the array is its own class.

Pretty much everything else you said went completely above my head. I am really new at this.

 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Scotty Steven wrote:I just set it up with a main method for testing purposes only. It is part of a larger program, and the array is its own class.

Pretty much everything else you said went completely above my head. I am really new at this.



700 data entries do not belong in the source code. They belong in a file or database.

As for the rest, well, you've heard of defining classes to represent the concepts you're dealing with, right? Like if I said that a school registration program would have a Course class and a Student class, or a banking program would have a Customer class and an Account class, you'd understand that, right? Well, here you're defining a glossary, and each entry has a term ("Java") and a definition, ("A programming language that..."), so doesn't it make sense to have a class like GlossaryEntry, with "term" and "definition" member variables.?
 
Scotty Steven
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It does make sense, but I have no clue how to even approach something like that. I trying to teach myself programming for fun, and I really haven't that far into my learning. I decided to create a project where every new skill I learn, I practice it on a digital cheat-sheet project.

Oh boy. Now I get to try and learn database design. That sounds like a huge undertaking.
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Scotty Steven wrote:It does make sense, but I have no clue how to even approach something like that. I trying to teach myself programming for fun, and I really haven't that far into my learning.



Okay, fair enough. So when you get to that point in your education, come back to this program and see if you can improve it.

Oh boy. Now I get to try and learn database design. That sounds like a huge undertaking.



It is huge, and I wouldn't go there yet if I were you. Get the basics of Java down first. Start with just a text file of your entries. Tackle the database later.

Good luck!
 
Scotty Steven
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sounds good. I'm doing the practice of the "core" concepts in command line, but then I'm trying to apply them to Swing display. So, in theory, I'm trying to learn two for one!
 
What a stench! Central nervous system shutting down. Save yourself tiny ad!
The Low Tech Laboratory Movie Kickstarter is LIVE NOW!
https://www.kickstarter.com/projects/paulwheaton/low-tech
reply
    Bookmark Topic Watch Topic
  • New Topic