List<String> readText(BufferedReader in) throws IOException {
List<String> l = new ArrayList<String>();
String s;
while((s = in.readLine()) != null) l.add(s);
return l;
}
Is this what you mean? Use (String[])l.toArray() if you really need an array for some reason.
Name:
Anonymous2008-02-19 17:22
op here.
let me describe what's going on and sorry for my english
there is a text file with several lines of text, and the number of lines is not known.
I need a way to grab the lines from the BufferedReader/FileReader and sort of store it - as in an array -, because later I will give this array to another class that will do a lot of things, like swap chars from chars, remove chars, etc...
but arrays need an implicit number to be created, and I don't know if later on I will be able to perform such swap/remove characters*...
ArrayList could be good, but can I do things* with the stored strings?
thank you and sorry for my english/nervousness? =/
Name:
Anonymous2008-02-19 17:38
>>8
Yeah, do use an ArrayList or similar to store them, not a regular array. What you can do with the Strings inside has nothing to do with the way you store them. You'll be calling them as String s = alist.get(i) anyway, so you'll be dealing with a regular String object.
Strings are immutable in Java, so swapping/removing chars is going to be annoying, but not particularly hard, thanks to String.toCharArray() and the fact that String can take an array of chars in its constructor.
>>9 char [] s = alist.get(i).toCharArray() would be shorter. Either way, the basic idea is the same.
Just use ArrayList.set(int, Object) to update the String in the ArrayList when you're done with it.
Anyway, an Enterprise-grade design pattern is to use a constant factory -- you just can't know when those constants change!
type null = ConstantFactory.newConstant("NULL");
Name:
Anonymous2008-02-20 10:42
>>25
Design patterns aren't specific to Java, dipshit. The GoF used Sepples and Smalltalk, and didn't even mention Java.
Also, type is not a Java keyword.
Name:
Anonymous2008-02-20 10:51
>>26 Design patterns aren't specific to Java, dipshit. The GoF used Sepples and Smalltalk, and didn't even mention Java.
Did I say they were? Also, type is not a Java keyword.
I used that because I don't know Java (but I just read some Java code where there was this type called ``Object,'' would that be right?).
You obviously know Java... get out of my /game/.
Name:
Anonymous2008-02-20 11:04
>>27 Did I say they were? You know Java... LOL!
You implied I had to know Java to recognise misuse of design patterns, even though Java is a niggerly easy language to just read if you know any C-derived language even a tiny bit, thereby implying that you didn't know design patterns exist independently of the language, and in fact predate it.
I used that because I don't know Java
You also don't know anything about design patterns. In fact, you don't know anything even remotely relevant to this thread, yet you continue to shit it up. gb2/pr/
(but I just read some Java code where there was this type called ``Object,'' would that be right?).
No. null isn't a constant (as Java is too high-level for that sort of faggotry) or an object (as Java is OO in the same sense that Sepples is OO; that is, not really), or even a primitive. It's just a keyword.
You obviously know Java... get out of my nigger.
I do know Java, and design patterns, which means I have an informed opinion on them, which I can back up with more than just failed attempts at shitty satire. You, on the other hand, are an ignorant dickfuck.
Java is a crap language suffering from ENTERPRISE cancer, but you aren't in any position to say so, as you don't know anything about it.
Design patterns are retarded bullshit, but again, you aren't in any position to know this.
The fact that you're proud of your ignorance leads me to believe you're still in high school (or midle school). /pr/ will value your skills more highly than /prog/.
>>28
I DONT HAVE TO GIVE REASONS FOR MY AGRUMENTS BECAUZE I AM EXPART PROGRASMMERAR!!!11111111111 I ROTE A C COMPILER USIN SNAI SEE WHEN WAS I FIVE YEARS OLD AND THEN THE ISO SPCEC WHEN I SAW INNE YARD OL!D11111111
>>30
Well I am not an "/b/." You have no right to call me that if I made mistakes. This site should have some rules about harrassments, threats, and name calling. I am still in the need of more help in that regards
Name:
Anonymous2008-02-20 11:32
>>28
GTFO my fucking /prog/, humorless anticudder.