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.
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.
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.
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.
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 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.?
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.