boen_robot Posted April 5, 2008 Share Posted April 5, 2008 I'm working with JAVA these days, part of efforts for impoving my API, but before going into the deep, I wanted to learn some basic JAVA I/O, and one that would work from PHP as well. Standard byte streams seem to be it.The program below is supposed to be like "echo" a bit. You write something (for example "test"), and get "Default string."+the text you typed (example: "Default string. test"). public class Main { public static void main(String[] args) { try { boolean keepReading = true; java.util.ArrayList line = new java.util.ArrayList(); while(keepReading) { int character = System.in.read(); if (character != '\n') { line.add(line.size(), character); }else { String lineContents = "Default string. "; for(int i = 0; i<line.size(); i++) { lineContents.concat(new String(line.get(i).toString())); } System.out.println(lineContents); System.exit(0); } } } }} The problem is instead I always get only "Default string. ". The for loop doesn't seem to be working, or... something else, I don't know for sure. What could possibly be the reason?Also, at compile time, I get the warning:Main.java:18: warning: [unchecked] unchecked call to add(int,E) as a member of the raw type java.util.ArrayListwith line 18 being line.add(line.size(), character); What on earth does this warning mean? How could I avoid it and what problems could this cause? Is it possible its related to the fact I don't see anything from the input?If I'm taking the wrong approach, how would you suggest I echo out something from the input stream? Oh, and no console allowed. PHP doesn't support it, I've tried. Link to comment Share on other sites More sharing options...
boen_robot Posted April 6, 2008 Author Share Posted April 6, 2008 Nevermind. Got my question answered elsewhere. Shows how much W3Schools needs a JAVA forum. Link to comment Share on other sites More sharing options...
Synook Posted April 7, 2008 Share Posted April 7, 2008 "immutable"... being grown with PHP where there's no such thing, I think this is one word I'll keep hating for a long, long time.What about constants? Link to comment Share on other sites More sharing options...
boen_robot Posted April 7, 2008 Author Share Posted April 7, 2008 What about constants?When I use constants, I use them exactly because I don't want thir values to change. In JAVA, when I use Strings, I use them because that's the better way of representing characters than a sequence of bytes, but I still want them to be changeable, hence they are stored in a variable (which I'd expect by defintion, to be able to vary). The same goes with Arrays. I use ArrayList objects in preference of Arrays because they're not immutable like arrays. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.