Covert an int value into a ninteger
How do i convert an int value into an integer.Please help
http://java.sun.com/j2se/1.5.0/docs/guide/language/autoboxing.html
Since JDK 1.5, you can do the below:
public class TestAB {
public static void main(String[] args) {
int i = 0;
Integer a = ++i;
System.out.println(a);
i = 1 + a;
System.out.println(i);
}Message was edited by:
John60
Similar Messages
-
Store int values into dynamic array
Hello all,
I'm a newbie in JAVA whose want to store int values (coming from a resultset) into an dynamic array. I know that normally to create a "dynamic array" you'd better use a Vector, but it seems that I don't know how to use it correctly (throws me a exception as : Incompatible type for method. Can't convert int[] to java.lang.Object[]).
Thanks in advance
STFI want to use the copyInto method of the vector, but it throw me an exception as ')' expected
I include a snip of my code below ;
Vector v= new Vector();
Vector vv=new Vector();
String[] labels=new String[v.size()];
Integer[] values=new Integer[vv.size()];
cont=rs.getInt("COUNT(CASE_ID_)");
vv.add(j,new Integer(cont));
log=rs.getString("ORIG_SUBMITTER");
v.add(j,new String(log));
v.copyInto(String[] labels);
vv.copyInto(Integer[] values); -
Checking if input into JTextField is an int value
Is there any way that you can check whether the String entered into a JTextField represents an int?
Thanks for the help!
WallaceJTextField field = ...
try
int value = Integer.valueOf(field.getText).intValue();
catch(NumberFormatException)
// not a number
} -
URGENT: Covert a true - false value into a bit value
Hello :)
I have a problem, How can I convert a true false value into a bit value, because, I declare a variable value with true or false, that means that I have a 1 or a 0, (thinking about digital information)
for example, one this is my part of my code:
private boolean _x3 = true;
private boolean _x5 = false;
private boolean _x6 = true;
private boolean _x7 = false;
private boolean _x9 = true;
private boolean _x10 = false;
private boolean _x11 = true;
public boolean CheckP1(boolean pP1)
pP1 = x3^x5 ^_x7 ^_x9 ^_x11;
return pP1;
This method will send a true or false value, but now I have two doubts, one of them, is, how can get this value, and the second value, how can I conver this value into a bit value
Thank you so much :)
NatalyLook at a BitSet to hold your boolean values.
Check the API for details.
JJ -
How to convert ascii value into character and vice versa
Hello the java world people,
I want to convert each characters from my array into their corespondent ascii value and vice versa, how can I do that ?The term "ASCII" is often used very loosely.
Java char values are UNICODE and the ASCII codes are indentical to UNICODE characters in the range 0 .. 127. UNICODE values 128 and above don't have coresponding ASCII values, though 128-255 corespond to ISO-8859-1 which is one of the encodings often called "extended ASCII".
As shown above you can covert between chars and coresponding int value simply with a cast, but you should be aware that the more exotic characters will not give you sensible values. -
How to get int value from [session.getAttribute("String")]
i am not able to get int value from the following statiment
int i=session.getAttribute("String");
i also try by casting it into int but it dont work, can somebody help me in this regardabuu wrote:
i am not able to get int value from the following statiment
int i=session.getAttribute("String");
i also try by casting it into int but it dont work, can somebody help me in this regard
Integer i=(Integer)session.getAttribute("String");
i.intValue();but know how it is working. that is useful.
Diablo. -
How to insert values into an array of class
Hello everyone,
I need help in inserting values into an array of class, which i have read from a file.
Length of the array is 5. I should insert values one by one into that array.
If the array is full (if count = 5), then I should split the array into 2 arrays
and adjust the values to left and right with median.
I'm getting an ArrayBoundException .. can anybody help me out ?
Thanks in advance
Here is my code..........
import java.util.*;
import java.io.*;
public class Tree
static String second;
static String first;
static int count = 5;
public void insert(int f1,int s1, int c)
if(c!=0)
Record[] rec = new Record[4];
for (int i = 0; i < 5; i++)
rec[i] = new Record();
for(int i = 0; i<=4;i++)
rec.x = f1;
rec[i].y = s1;
else
System.out.println("yes");
public static void main(String[] args)
Tree t = new Tree();
try
FileReader fr = new FileReader("output.txt"); // open file
BufferedReader br = new BufferedReader(fr);
String s;
while((s = br.readLine()) != null)
StringTokenizer st = new StringTokenizer(s);
while(st.hasMoreTokens())
first = st.nextToken();
second = st.nextToken();
// System.out.println("First-->"+first+" "+"Second-->"+second);
int fir = Integer.parseInt(first);
int sec = Integer.parseInt(second);
t.insert(fir, sec, count);
fr.close(); // close file
catch (IOException e)
System.out.println("Can't read file");
class Record
public int x,y;Hi qwedwe.
Record[] rec = new Record[4];
for (int i = 0; i < 5; i++)
rec[i] = new Record();
}Here is your error: you have an array of 4 Records, but you create and (try to) insert 5 Record-instances.... try:
Record[] rec = new Record[c];
for (int i = 0; i < c; i++)
rec[i] = new Record();
}Regards,
Norman -
How to get the section value into configurator developer page
Hi,
I am working on configurator developer, Can I get the section value into the configurator developer page by any setup. If possible means please help me on that.
Thanks advance,
GopiI thought the same.Thanks for confirming...I tried with loop approach.but i am unable to get decimal part...
eg if my values are 12.25 and 123.12....my below code ignores decimal points..i know since i am using Number, it is happening..but could you please let me know how can i get decimal values also..
OAViewObject vo = (OAViewObject) am.findViewObject("XXXXInvDistributionsVO1");
vo.first();
Number grossamount = 0;
for (int i=0;i< vo.getRowCount();i++) {
// BigDecimal grossamount1 = new BigDecimal((vo.getRowAtRangeIndex(i).getAttribute("Amount")));
grossamount = ((oracle.jbo.domain.Number)vo.getRowAtRangeIndex(i).getAttribute("Amount")).intValue();
System.out.println("grossamount "+grossamount); // it ignores and prints decimal points
BigDecimal grossamount1 = new BigDecimal(grossamount.intValue());
System.out.println("grossamount1 "+grossamount1); // it ignores and prints decimal points
vo.next();
Thanks
Raj -
Please help - Joining three tables and get row values into Column. Please help!
Hi,
There is a SourceTable1 (Employee) with Columns like EmployeeID,Name,DOB.
There is a sourcetable2 (EmployeeCode) with columns like EmployeeID,Code,Order.
There is a source table 3 #EmployeeRegioncode and its columns are (EmployeeID , RegionCode , [Order]
The target table 'EmployeeDetails' has the following details. EmployeeID,Name,DOB,Code1,Code2,Code3,Code4,regioncode1
regioncode2 ,regioncode3 ,regioncode4
The requirement is , the value of the target table columns the Code1,code2,code3 ,code4,code5 values should
be column 'Code' from Sourcetable2 where its 'Order' column is accordingly. ie) Code1 value should be the 'Code' value where [Order] column =1, and Code2 value should be the 'Code' value where [Order] =2, and so on.
Same is the case for Source table 3- 'Region code' column also for the columns regioncode1
regioncode2 ,regioncode3 ,regioncode4
Here is the DDL and Sample date for your ref.
IF OBJECT_ID('TEMPDB..#Employee') IS NOT NULL DROP TABLE #Employee;
IF OBJECT_ID('TEMPDB..#EmployeeCode') IS NOT NULL DROP TABLE #EmployeeCode;
IF OBJECT_ID('TEMPDB..#EmployeeDetails') IS NOT NULL DROP TABLE #EmployeeDetails;
---Source1
CREATE table #Employee
(EmployeeID int, Empname varchar(20), DOB date )
insert into #Employee VALUES (1000,'Sachin','1975-12-12')
insert into #Employee VALUES (1001,'Sara','1996-12-10')
insert into #Employee VALUES (1002,'Arjun','2000-12-12')
---Source2
CREATE table #EmployeeCode
(EmployeeID int, Code varchar(10), [Order] int)
insert into #EmployeeCode VALUES (1000,'AA',1)
insert into #EmployeeCode VALUES (1000,'BB',2)
insert into #EmployeeCode VALUES (1000,'CC',3)
insert into #EmployeeCode VALUES (1001,'AAA',1)
insert into #EmployeeCode VALUES (1001,'BBB',2)
insert into #EmployeeCode VALUES (1001,'CCC',3)
insert into #EmployeeCode VALUES (1001,'DDD',4)
insert into #EmployeeCode VALUES (1002,'AAAA',1)
insert into #EmployeeCode VALUES (1002,'BBBB',2)
insert into #EmployeeCode VALUES (1002,'CCCC',3)
insert into #EmployeeCode VALUES (1002,'DDDD',4)
insert into #EmployeeCode VALUES (1002,'EEEE',5)
---Source tbl 3
CREATE table #EmployeeRegioncode
(EmployeeID int, RegionCode varchar(10), [Order] int)
insert into #EmployeeRegioncode VALUES (1000,'xx',1)
insert into #EmployeeRegioncode VALUES (1000,'yy',2)
insert into #EmployeeRegioncode VALUES (1000,'zz',3)
insert into #EmployeeRegioncode VALUES (1001,'xx',1)
insert into #EmployeeRegioncode VALUES (1001,'yy',2)
insert into #EmployeeRegioncode VALUES (1001,'zz',3)
insert into #EmployeeRegioncode VALUES (1001,'xy',4)
insert into #EmployeeRegioncode VALUES (1002,'qq',1)
insert into #EmployeeRegioncode VALUES (1002,'rr',2)
insert into #EmployeeRegioncode VALUES (1002,'ss',3)
---Target
Create table #EmployeeDetails
(EmployeeID int, Code1 varchar(10), Code2 varchar(10),Code3 varchar(10),Code4 varchar(10),Code5 varchar(10) , regioncode1 varchar(10),
regioncode2 varchar(10),regioncode3 varchar(10),regioncode4 varchar(10))
insert into #EmployeeDetails VALUES (1000,'AA','BB','CC','','','xx','yy','zz','')
insert into #EmployeeDetails VALUES (1001,'AAA','BBB','CCC','DDD','','xx','yy','zz','xy')
insert into #EmployeeDetails VALUES (1002,'AAAA','BBBB','CCCC','DDDD','EEEE','qq','rr','ss','')
SELECT * FROM #Employee
SELECT * FROM #EmployeeCode
SELECT * FROM #EmployeeRegioncode
SELECT * FROM #EmployeeDetails
Can you please help me to get the desired /targetoutput? I have sql server 2008.
Your help is greatly appreciated.select a.EmployeeID,b.code1,b.code2,b.code3,b.code4,b.code5,c.Reg1,c.Reg2,c.Reg3,c.Reg4 from
#Employee a
left outer join
(select EmployeeID,max(case when [Order] =1 then Code else '' end) code1,
max(case when [Order] =2 then Code else '' end)code2,
max(case when [Order] =3 then Code else '' end)code3,
max(case when [Order] =4 then Code else '' end)code4,
max(case when [Order] =5 then Code else '' end)code5 from #EmployeeCode group by EmployeeID) b
on a.EmployeeID=b.EmployeeID
left outer join
(select EmployeeID,max(case when [Order] =1 then RegionCode else '' end) Reg1,
max(case when [Order] =2 then RegionCode else '' end)Reg2,
max(case when [Order] =3 then RegionCode else '' end)Reg3,
max(case when [Order] =4 then RegionCode else '' end)Reg4 from #EmployeeRegioncode group by EmployeeID) c
on a.EmployeeID=c.EmployeeID
Thanks
Saravana Kumar C -
How CallableStatement in JSP use setDate() method to insert the date value into DB?
Dear all,
I met a strange error message when i insert a date value into DB via JSP call PL/SQL procedures.
The error seems caused by the setDate(index, date) method with CallableStatement.
The message is: Can not find the setDate(int, java.util.Date) method in the CallableStatement interfaces.
Any ideas?
Thanks advanced.Thank you!:)
I solved it using this:
String name="david";
stmt = con1.createStatement();
String prikaz1 = "INSERT INTO table (id,age,surname,name) IN 'C:\\Users\\David\\Desktop\\db.mdb' SELECT id,age,surname,' " + name + " ' FROM table2";
stmt.executeUpdate(prikaz1); -
Html check box pass more than one value into bean
Hi all'
I have group of check box in html , I need to pass more than one value
into bean an ddisplay in jsp
what do i do wrong
private Vector select =new Vector();
private String mybox =null;
public download() {
again();
/* Accessor Methods */
private void addmybox(String name){
select.addElement(name);}
public void setMybox(String name) {
mybox = name;
public String[] getMybox() {
String[] s = new String[select.size()];
select.copyInto(s);
return s;
in my htmli have <%
String[] mybox= format.getMybox();
for (int i=0; i<Mybox.length; i++) {
<%= format.getMybox%>
%>
i got error at <%= format.getMybox[i]%>Hi ram,
thank you, I don't have ideal in my mide .
in my jsp I have
<td> <input type=checkbox name=mybox value=<%= link.getNewNum()%>></td>in my servlet I have something like
String[] checked = request.getParameterValues("mybox");
try {
conn = DriverManager.getConnection("jdbc:microsoft:sqlserver://localhost:1433","A#$","RE@89");
conn.setCatalog("sequences");
stmt = conn.createStatement();
for(int i=0; i<checked.length; i++){
String select=checked;
String Sql=" select NewNum, Name, Length, Segment, Sequence";
Sql+=" from Sec04";
Sql+=" where NewNum='"+select+"'";
Sql+=" union";
Sql+=" select NewNum, Name, Length, Segment, Sequence";
Sql+=" from MySec";
Sql+=" where NewNum='"+select+"'";
Sql+=" union";
Sql+=" select NewNum, Name, Length, Segment, Sequence";
Sql+=" from Sec03";
Sql+=" where NewNum='"+select+"'";
Sql+=" union";
Sql+=" select NewNum, Name, Length, Segment, Sequence";
Sql+=" from Sec02";
Sql+=" where NewNum='"+select+"'";
Sql+=" union";
Sql+=" select NewNum, Name, Length, Segment, Sequence";
Sql+=" from Sec01";
Sql+=" where NewNum='"+select+"'";
rs = stmt.executeQuery (Sql);
while(rs.next()) {
String Name = rs.getString("Name");
String Segment =rs.getString("Segment");
String Length = rs.getString("Length");
String Sequence = storeSequenceData(rs.getString("Sequence"));
String SContent = Name + " ," Segment ", "+ Length + "\n" +Sequence ;
now I want
String SContent = Name + " ," +Segment + ", "+ Length + "\n" +Sequence +"\n" + Name+"Segment+","+length+"+"\n" +Name......untill the end
it sees like I need to look st on shipp car. is that right??
Thank you !! -
How to prevent from inserting two similar values into DB?
Hi,
I wanted to know how we can prevent from inseting two similar values into the database, e.g the user id which should be unique. Here is some sample code, Please help me.
String s10 = req.getParameter("T10");
String s11 = req.getParameter("T11");
rs = st.executeQuery("select * from Register where userid='"+s10+"' ");
if(rs.next())
sos.println("Sorry the user already exists");
else
int x = st.executeUpdate("insert into Register values('"+s1+"','"+s2+"','"+s3+"','"+s4+"','"+s5+"',"+s6+","+s7+",'"+s8+"','"+s9+"','"+s10+"','"+s11+"')");
Thaks in advance
UmaHi reddy
Your code works will be perfect with slight changes whucah are as below:
String s10 = req.getParameter("T10");
String s11 = req.getParameter("T11");
rs = st.executeQuery("select * from Register where upper(userid)='"+s10.toUpperCase()+"' ");
if(rs.next())
sos.println("Sorry the user already exists");
else
int x = st.executeUpdate("insert into Register values('"+s1+"','"+s2+"','"+s3+"','"+s4+"','"+s5+"',"+s6+","+s7+",'"+s8+"','"+s9+"','"+s10+"','"+s11+"')");
In the above Query we will get a unique userids it may be smallcase or Uppercase
This will help u
Cheers
Rambee -
Insert float value into ms sql server
Hi.
How do I insert a float value into my ms sql db.
The Code:
select.setFloat( 4, theForm.getVaerdi() );ERROR:
"MakeClapetInsertAction.java": Error #: 300 : method setFloat(int, java.lang.Float) not found in interface java.sql.PreparedStatement at line 89, column 12setFloat takes a float primitive, not a Float object.
select.setFloat( 4, theForm.getVaerdi().floatValue() ); -
Add values into view controller 's attribut
Dear All!
I would like store some data in the view controller.
It is a value attribut and has the type java.util.List.
1. How can I add now many values into this attribut
2. How can I get this values again ?
Regards
sasHi Sas,
The list is similar to any value node.
You can add elements like this.
for(int i=0;i<SIZE;i++)
IPrivate<viewname>.I<node>Element ele = wdContext.create<node>Element();
ele.set<attribute>(" "+i);
wdContext.node<node>().addElement(ele);
You can get elements like this:
for(int i=0;i<SIZE;i++)
IPrivate<viewname>.I<node>Element ele = wdContext.node<node>().get<node>().ElementAt(i);
ele.get<attribute>();
wdContext.node<node>().addElement(ele);
regards,
Siva -
Need help to convert this format of string in a int value?
public static int isNumber( String number, int defaultValue ) {
int result;
try {
result = Integer.parseInt(number);
} catch( Exception e ) {
result = defaultValue;
return result;
}Hi, I have the above method that converts a string Number into a int value. It works fine if the string is a normal number 234 (without spaces) but I have a string in the following format:
*(space)�23,000(space).*
That is I have a "space" then a "Pound" sign then two numbers then a comma followed by three numbers and then a space again.
Is there any way I can convert this format into a simple int value?
Thanks for any guidance.
ZubHi, I tried the following code but it don't seem to work
public static int isNumberTrimSpaces( String number, int defaultValue ) {
number.trim();
String parsed = "";
for (int i = 0 ; i < number.length() && number.charAt(i) != ',' ; i++)
if (Character.isDigit(number.charAt(i))) {
parsed += number.charAt(i);}
int result;
try {
result = Integer.parseInt(number);
} catch( Exception e ) {
result = defaultValue;
return result;
}Any Ideas? Also will the loop get rid of the pound sign?
Maybe you are looking for
-
Getting 404 error when try to access website
Hello...I have an iweb created website hosted at GoDaddy. Yesterday I did major changes on the site and uploaded it. If I use the bookmark I have established I can access the site just fine, and it is the current site. if i type in the url I get a 40
-
Some font families don't render correctly when I use them with Graphics2D, namely Wingdings. It just renders empty boxes instead of the font's character. Any ideas as to why this is happening would be great. Thanks, CyberOppy
-
Hi all, Is Essbase Excel add ins still available with V11 Cheers
-
Comments on wiki from mobile device do not show up!
Hello, We have deployed our wiki server but we are having a problem. You can add comments when accessing the server from a mobile device but the comments disappear if you go back to browse for wikis. I have updated to 10.6.7 and deleted and re-added
-
Comment spécifier le chemin d'enregistrement du pdf via un bouton "saveas" en Javascript ?
Bonjour, Tout d'abord, j'utilise LiveCycle designer ES3 sur PC. J'ai créé un formulaire comprenant un bouton exécutant un script Java qui ouvre une boite de dialogue "enregistrer sous..." comme celui-ci : \\ Script enregistrer-sous\\ app.execMenuItem