[brailleblaster] Re: Java question: Extracting an integer from a String

  • From: "John J. Boyer" <john.boyer@xxxxxxxxxxxxxxxxx>
  • To: brailleblaster@xxxxxxxxxxxxx
  • Date: Wed, 21 Mar 2012 10:09:06 -0500

Thanks. parseInt did the trick. The name fooled me when I looked at 
Integer. 

John

On Wed, Mar 21, 2012 at 11:26:50AM -0000, Michael Whapples wrote:
> I think the answer is in the Integer class. Here is the java documentation 
> for Integer 
> http://docs.oracle.com/javase/1.5.0/docs/api/java/lang/Integer.html
> 
> Look at:
> public static int parseInt(String s)
> and
> public static Integer valueOf(String s)
> 
> The first will give you an int, the primitive type where as the second 
> gives you an Integer object, you may want to look into the differences and 
> how Java handles them including its autoboxing. This is one thing Scala 
> gets away from, they believe the use of primitives is incorrect for a true 
> OO language.
> 
> Also there are variations of these methods where you can give a radix, 
> however for decimal integers the ones I gave are fine as they use a radix 
> of 10.
> 
> You probably will need to manually loop through the array of strings 
> though, I don't think there is a standard Java method for converting an 
> array of String into an array of ints.
> 
> Michael Whapples
> 
> -----Original Message----- 
> From: John J. Boyer
> Sent: Wednesday, March 21, 2012 10:50 AM
> To: brailleblaster@xxxxxxxxxxxxx
> Subject: [brailleblaster] Java question: Extracting an integer from a String
> 
> In integrating UTDML with BrailleBlaster I have to deal with the index
> attribute of the <brl tg. It contains a list of positions expressed as
> decimal numbers separated by spaces. The split method of the String
> class converts this into an array of String objects, each containing one
> of these numbers. The next step is to convert this array into an array
> of int. However, I can't find a method that takes a String and returns
> the integer that it contains either in the String or Integer classes.
> Where might it be?
> 
> Thanks,
> John
> 
> -- 
> John J. Boyer; President, Chief Software Developer
> Abilitiessoft, Inc.
> http://www.abilitiessoft.com
> Madison, Wisconsin USA
> Developing software for people with disabilities
> 
> 

-- 
John J. Boyer; President, Chief Software Developer
Abilitiessoft, Inc.
http://www.abilitiessoft.com
Madison, Wisconsin USA
Developing software for people with disabilities


Other related posts: