Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
clayburn
Mar 6, 2007

Cammy Cam Juice
Simple question I think. I have a very long string, that I want to take all n-length substrings out of and place into an array. For example if n is 5 and the sentence is "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt whatever", I would want string one to be "Lorem ipsum dolor sit amet,"
, string two to be "ipsum dolor sit amet, consectetur", string three to be "dolor sit amet, consectetur adipisicing", and so on. What would be the best way to go about this? I am having a hard time getting anything to work really.

Adbot
ADBOT LOVES YOU

clayburn
Mar 6, 2007

Cammy Cam Juice
Haha it might be homework. I really just needed a point in the right direction like you gave, just some methods to look at. I've considered putting the words in some sort of array, I'm just worried about the efficiency of putting them there in the first place. I'll definitely check those methods out though, thanks.

clayburn
Mar 6, 2007

Cammy Cam Juice
I have a question about the HashMap class. I have populated a HashMap with a simple object I have created, basically consisting of two strings. One of these strings holds a segment of text from a file, the other holds the file name. What I want to do is to use the HashMap.contains method to determine if a particular string matches any of the text segments, and then use whatever get method is in the class to determine the file name. I figured that overriding the hashcode method would do the trick; I defined the hashcode method of the class to return the hashcode value of the string that we will be searching for. Apparently, this doesn't quite do the job. I am fairly new to hash tables, so if anyone could give me a few tips it would be very appreciated.

clayburn
Mar 6, 2007

Cammy Cam Juice
I had a nice long post typed up and lost it due to the forum maintenance. Basically I asked if this code:
code:
hashMap hm = new hashMap();
hm.put("foo", "file1.txt");
if(hm.containsKey("foo")
{
      String fileName = hm.get("foo");
}
would evaluate the if statement's condition to true and have fileName reference the string "file1.txt." If that would work then I think I understand it now.

edit: This works perfectly, even better than I had hoped it would. Thanks for the help.

clayburn fucked around with this message at 04:51 on Apr 22, 2008

clayburn
Mar 6, 2007

Cammy Cam Juice
It looks like I have another problem with my HashMap involving collisions. Looking at my data set, I know for a fact that collisions are happening, and this is causing problems for me. Every time that I search for a value at a specific key, I only get one of the values, where sometimes I may want the other value. For example, if "foo" and "bar" are stored at the same key, I will only ever get "foo" even though sometimes I may want to find any string that is not "foo." Is there any way to go about this? I have read the API entry for HashMaps over and over and cannot seem to find a solution to this.

clayburn
Mar 6, 2007

Cammy Cam Juice
Yes, and I'm starting to get the impression that it was a really bad idea. I thought that it would simply handle that as a collision and store the object somewhere else that would still be accessible.

clayburn
Mar 6, 2007

Cammy Cam Juice
I've never really used done any sort of GUI stuff before, but I am currently trying to implement some Swing stuff using NetBeans GUI Builder. I have two problems that I can't seem to figure out. Basically I want to browse file much like the Windows Explorer does. I want a file tree on the left column with the detailed list view using the rest of the window. I can not figure out how to get the JTree to point to the file structure or how to make sortable columns in a JList. Is there some easy way to do either of these things or am I going to have to hack something together?

clayburn
Mar 6, 2007

Cammy Cam Juice
Anyone know how to restore the build.xml file that NetBeans creates? I have a project and somehow mine got messed up and now it won't compile.

Adbot
ADBOT LOVES YOU

clayburn
Mar 6, 2007

Cammy Cam Juice
Well I had it working fine, then I started working on another project and since then the other one has been messed up. Now that you say that though I think I may know more what the problem is, so thanks for pointing that out.

Is there a way to fix the nbprojects files? I still have all of the source code but those have somehow gotten messed up.

clayburn fucked around with this message at 00:32 on Jul 18, 2008

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply