The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
September 2000

Advertisement

Advertisement

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.

Message:

Typecasting

Posted by Fred Ward on November 20, 2001 at 5:34 PM

Integer.parseInt() will do the trick.


> 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;
> while(st.hasMoreTokens()){
> 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();
>
>
> }
> }





Replies:

Sponsored Links



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