+ 1
Java - split and parse
Im reading in 3 inputs from a file that are on the same line and splitting it -i can add the 3 split pieces into an array - but what if i want to send each piece to my object as parameters for the constructor? My instructions are to use parse and split to save the data from my file and up to this point ive only saved each as its own variable using the different variations of next()
2 odpowiedzi
+ 13
A code example would be quite helpful for us ;)
Did you already save your parsed string to an array?
Then pass the values to the constructor like this:
MyClass myClass = new MyClass(arr);
You can handle the array in the constructor like this:
public MyClass(String[] arr) {
s1=arr[0];
s2=arr [1];
// and so the on
}
+ 1
Easiest thing: Give your object an additional constructor and let it handle the array.