Two Laptop Bag
The moose likes Beginning Java and the fly likes Converting Strings to a Short datatype Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "Converting Strings to a Short datatype" Watch "Converting Strings to a Short datatype" New topic
Author

Converting Strings to a Short datatype

Veni Velkoor
Ranch Hand

Joined: Oct 17, 2001
Posts: 65
Hello,
I am trying to convert a String field to a Short type and cast desn't seem to work. Any advice willbe useful. My code is as follows--
String sParmValue = "";
short len = 0;
short csrposn = 0;
.
.
.
.
}else
if (sParmName.equals("c__Scrn__Cposn_I")) {
LL350C.setC__Scrn__Cposn_I(sParmValue);
}
Now, I the setC__Scrn__Cposn variables of Short type and sParmValue is a String. SO how can I convert sParmValue to type Short so that I can assing it to C__Scrn__Cposn__I.
Thanks!!
Veni.
Manish Hatwalne
Ranch Hand

Joined: Sep 22, 2001
Posts: 2573

Short.parseShort(sParmValue) should do this.
HTH,
- Manish
Dave Vick
Ranch Hand

Joined: May 10, 2001
Posts: 3244
Veni
What you want is the parseShort metod in the Short class. It takes a String and returns a short. You have to put it in a try/catch block to catch the possible NumberFormatException it can throw.
something like is what you want:

hope that helps



------------------
Dave
Sun Certified Programmer for the Java� 2 Platform


Dave
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Converting Strings to a Short datatype
 
Similar Threads
DB: Keeping track of deleted records
Fast way to write and read buffered data
how to convert string to short
Wrappers
append 0 with 0 to 9(0 as 00, 1 as 01...., 9 as 09) ?