LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 08-20-2007, 01:12 AM   #1
scottcky1985
LQ Newbie
 
Registered: Aug 2007
Posts: 2

Rep: Reputation: 0
Question in java...


-
Guest.java
-
private Integer _Id;

public Integer getId()
{
return _Id;
}

public void setId(Integer pId)
{
_Id = pId;
}

-
a.java
-
String strGuestID = "";
String GuestID = "";

GuestID = strGuestID.substring(0, 4);




The GuestID is get from the text file, so GuestID is String. Now, i would like to set the GuestID in Guest.java. The problem is the GuestID in a.java is String but in Guest.java is Integer, so may i know how to convert String to Integer in java?
 
Old 08-20-2007, 02:02 AM   #2
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,371

Rep: Reputation: Disabled
If you actually want to create an Integer object from a string (i.e. an object of class Integer, rather than a normal int), then you can use the Integer constructor that takes a string:

Integer i = new Integer("2");

If you just want to get the integer from the string into a "normal" int variable, then use the parseInt method of the Integer class:

int i = Integer.parseInt("2");
 
Old 08-20-2007, 02:17 AM   #3
gr8scot
Member
 
Registered: Jun 2007
Distribution: Debian
Posts: 73

Rep: Reputation: 16
GuestID = Integer.toString(Id);

GuestID = Integer.toString(Id);

converts integer to string

Last edited by gr8scot; 08-20-2007 at 02:18 AM. Reason: question is to convert string to integer, not integer to string
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Java question thefalling Programming 2 11-22-2006 02:01 PM
Java Question k1ll3r_x Programming 2 08-20-2005 08:10 PM
Java Question k1ll3r_x Programming 3 11-13-2004 04:27 AM
Question about Java Mega Man X Programming 3 12-27-2003 11:02 AM
java question TommyD Linux - Newbie 4 07-19-2003 04:29 PM


All times are GMT -5. The time now is 02:59 PM.

Main Menu
 
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration