Jump to content
Sign in to follow this  
boen_robot

An odd warning and a problem...

Recommended Posts

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.

Share this post


Link to post
Share on other sites

Nevermind. Got my question answered elsewhere. Shows how much W3Schools needs a JAVA forum.

Share this post


Link to post
Share on other sites
"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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×