The Artima Developer Community
Sponsored Link

Java Answers Forum
Converting an object to String and then to int

2 replies on 1 page. Most recent reply: May 23, 2005 1:29 AM by Kondwani Mkandawire

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 2 replies on 1 page
John Cahill

Posts: 1
Nickname: cahill
Registered: May, 2005

Converting an object to String and then to int Posted: May 19, 2005 12:20 PM
Reply to this message Reply
Advertisement
I need help in calling method xxx.getValueSelected that returns anobject from a JList , then convert it to a string, and then to an int,prior to storing it my declacre (int) number.

I am very new to Java.


Haik Hovsepian

Posts: 6
Nickname: haik
Registered: Oct, 2004

Re: Converting an object to String and then to int Posted: May 19, 2005 11:40 PM
Reply to this message Reply
Hello,
If you need to get selected index, you can use the method
xxx.getSelectedIndex()
it returns int.

Kondwani Mkandawire

Posts: 530
Nickname: spike
Registered: Aug, 2004

Re: Converting an object to String and then to int Posted: May 23, 2005 1:29 AM
Reply to this message Reply
> I need help in calling method xxx.getValueSelected that
> returns anobject from a JList , then convert it to a
> string, and then to an int,prior to storing it my declacre
> (int) number.
>
> I am very new to Java.


[code]
String myString = xxx.getSelectedValue().toString();
// next method will fail if selected item does not
// have an int format. getIndex returns index.
// if you want an int value of the selected String
// this is what you do. Not the previously suggested
int myInt = Integer.parseInt(myString);
[/code]

Flat View: This topic has 2 replies on 1 page
Topic: run ".cmd" file of java by jsp Previous Topic   Next Topic Topic: Help in - Java Web Start Setup

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use