My first question is this (and I'm sorry its such a noob question, its just been a really long time since I worked with Java, and an even longer time since working with I/O): How do I set up my code to access the external input in its totality? As in, not just line by line, or character by character (as in .read and .readline)?
My second question is how do I get the input data to be separated into individual strings? I believe that this can be done somehow using StringTokenizer, but I've also heard that this is obsolete, and having never used it before and being exceedingly rusty, I am hesitant give this a go. I have also read up on the String.split method. From what I've read, this would be exceptionally handy. As an example:
String[] result = "this is a test".split("\\s");
for (int x=0; x<result.length; x++)
System.out.println(result[x]);
This would result in a similar output to what I would like:
Quote
is
a
test
However, my true goal for this is to place the individual words that I find into a vector (so as to allow the words that are found as the input is read to be added into the vector (this was a suggested solution for me, but as to actually implementing this, I am unsure). The individual strings that are identical need to be printed as a single string (i.e. if there is three "the"s within the input file, the desired output prints a single "the") along with the number of times that specific string occurred within the input itself. This means that I need the program to separate the individual strings within the input file into words, identify and group words that are identical, count the total number of occurrences of said strings, and finally print the strings along with the total times the strings appear within the input file.
Not only was the possibility of using a vector suggested, but using a map was also suggested. From what little I know of maps, this would make sense, as a map consists of a key (a string, as it were) and a value (the number of times said string occurs within the input). However, I am extremely unfamiliar with the usage of maps (I know that map must be declared as an interface) and am unsure how to begin to implement this. All of the websites I've looked at show an exceedingly general case of using maps, but I'm unsure which methods would have a need to be implemented by a class.
For instance, when declaring the map interface, would it look something like this:
public interface Map<String,int> {
...
}
Next, I would like to put in the methods I would need to use for the map, but this is the part where I'm really confused by maps themselves. I'm sure I will need methods such as int put, which will set the value for the key and the matching int and Set<String>. My biggest concern on this comes from a portion of code I've seen:
Valuetype put (Keytype key, Valuetype value);
In this case, the value type would be int, and the keytype would be String. However, I'm not sure about the values for "key" and "value", as I would need many values within those specific variables.
Terribly sorry about my rant here, I'm just extremely confused as to how to go about approaching this problem, and this has been made worse since I have a very short deadline and have not had many hours of sleep.
Thanks in advance for any help, and if there are any questions (because I was probably unclear in my post, and for this I apologize), please don't hesitate to ask. Any help is appreciated.
Thanks,
Hellreaver

New Topic/Question
Reply
MultiQuote












|