I'm trying to figure out how BufferedReader works. The best idea I've come up with to read chars from text such as: 128, 23 , 10,..
is to read the line in as a String using 1d array for each line like so
I guess my questions are:
1. Will I have to use the BufferedReader-based control structure while(in.read()! = -1) or I will encounter issues? I have to ultimately load a 2D array, and don't know how to rig it if so.
2. If I am weeding out that which is not a number, is there a better method than .split(" ") bc what if its more than a space the size of " " ? Commas, larger spaces.... ( and the read() option only pulls characters in one at a time!)
If you're reading a text file, it's easier to use BufferedReader.readLine() and keep looping until it returns null.
As for splitting on more than just a single space, you need to determine what your rules are for the format of the file. If you're free to define them yourself, you can make the coding a little simpler by requiring exactly one space between numbers. But if someone else is defining the format, or if you want to be a bit more flexible, it's a pretty simple to create a regex for, say, "1 or more spaces" or "1 comma, possibly preceded and or followed by spaces". It all starts with clearly, precisely, and completely defining the format though.
Yeah I need to learn start learning regex. I opted to use Stringarr = string.split(" ") . Evidently it removes all the spaces in a string that has some characters and before loading into String array.
MyString.split(" "); will split only on space characters, not finding tabs etc. If you have double spaces, it will find an empty String between the spaces. You are probably better off splitting on "\\s+". That means any non‑zero number of whitespace characters. More details in this tutorial maybe in the predefined character classes section. there are many other regular expression tutorials.