Question
Java: How could I split this text file into two separate arrays? One as a string array that takes the first index and an int
Java: How could I split this text file into two separate arrays? One as a string array that takes the first index and an int array that takes the second index of every line in the file. Below is what i currently have. Part of the text file is below as well. Note: the StdIn.fromFile takes place of system.in, wordsCounts is what holds the input from the text file.I keep getting a Exception in thread "main" java.lang.NullPointerException
public static void main(String[] args) { StdIn.fromFile("data/WordsCounts.txt"); String wordsCounts = StdIn.readLine(); String[] keyArray= wordsCounts.split("\\s"); int vArray = Integer.parseInt(keyArray[1]); int [] valueArray = null; Arrays.fill(valueArray, vArray);
}
WordsCount.txt
a 2909 aa 1 aaabusiness 1 aamatter 1 aback 1 abandon 1 abandoned 10 abandoning 1 abandonment 1 abashed 1 abate 1 abated 1 abbaye 4 abbayein 1 abed 2 abhorrence 1 abided 1 abiding 1 abilities 1 ability 2 abject 1 ablaze 1 able 17 aboard 1 abode 1 abolished 2 abolishedexpression 1 abolishing 1 abolition 1 abominable 2 abounding 1 about 161 above 23 abreast 2 abridge 1 abroad 2 abrupt 3 abruptly 1 absence 8 absent 5 absolute 3 absolutely 7 absolving 1 absorbed 4 absorption 1 abstractedly 1 abstraction 3 absurd 1 abundance 1 abundant 4 abuse 1
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started