The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
September 2000



This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.


Typecasting in Java

Posted by cansada37 on November 19, 2001 at 9:41 PM

Does anyone know how to typecast a String in Java to an int.

I have an array Array[] [] that is of type int, and I am reading in input
from a file as a string

I write the following, but I get an error.
Array[k][l] = (int) st.nextToken();

Any suggestions would be greatly appreciated.

//Processing each line of the file
while(contents != null || contents != "911"){ // while the file is not empty
StringTokenizer st = new StringTokenizer(contents);
int linecount = 0;
for(int k = 0; k < 255; k++){//hard coding rows
for(int l = 0; l < 255; l++){ //hard coding columns
Array[k][l] = (int) st.nextToken();


  • Typecasting Fred Ward November 20, 2001 at 5:34 PM (0)

Sponsored Links

Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us