• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Difference in JSP

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello everyone,
I know this is a kind a very stupid question. Cuz a person who has already done database connectivityis asking this question. But these are some very easy questions due to which i am not able to learn jsp properply. Can anyone tell me what is the difference between :-
When i say
Integer p=new Integer(12);
and
int u[]={1,2,3,4,5,6,7}
Whenever i add the Integer in the vector it adds it without any difficulty. But when we add int u[] it gives me error messege "No match was found for method." I am using a vector where i am storing string and integer both. I can store string which has more than one values but i cannot store integer more than one values. For that i have to store one value at a time. My question is that how can i store a integer array in a vector so that i can call it in a vector. As my vector consist both a string and Integer. I can store string array when i write :-
String st[]={"Abhinav :-","Bharat :- ","Shalini:- ","Abhay:-","Deepak :-","Farhan :-","Hanish :-","Jacob :-"};
And then add it in a vector
c.add(st);
And later call it by
<%=v.elementAt(0);%>
0th element is my string array.
Can i call a integer array also like my string array.
Thanks in advance
abhinav
 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Sharma,
Since array (even array of primitive) is a special type of object and is a subclass of Object, therefore you can put in a vector.
You shouldn't have a problem adding the array of int in your vector. I have tried adding two arrays of int in a vector and it was OK.

int[] a = {1,2,3};
int[] b = {1,2,3};

Vector v = new Vector();
v.addElement(a);
v.addElement(b);
The code above compiled with no problem.
Hope this helps
Ted



 
Abhinav Sharma
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi ted,
Thanks for reply. But my problem still not solved. Well you can add int[] in a vector. But the problem is how to display the values inside the int.
My code is like this :-
<%
Integer p=new Integer(25);
int[] u = {1,2,3,4,5,6,7,8};
String st[]={"ID1 :- ","ID2 :- ","ID3 :- ","ID4 :- ","ID5 :- ","ID6 :- ","ID7 :-","ID8 :-"};
String st1[]={"Abhinav :- ","Bharat :- ", "Shalini:- ", "Abhay:- ", "Deepak :- ", "Farhan :- ","Hanish :- ", "Jacob :- "};
%>

<% for(int i=0;i<st.length;i++){
Vector v=new Vector();
v.addElement(st[i]);
v.addElement(st1[i]);
v.addElement(p);
v.addElement(u[i]);
%>
<%=v.elementAt(0);%>
<%=v.elementAt(1);%>
<%=v.elementAt(2);%>
<%=v.elementsAt(3);%><br>
<%}%>
I have used the same method to display a string value. And it does not shows any error. But when i use the same method for the int to display the values. it gives me the foloowing error.
"Errors reported by compiler :/jsp/WEB-INF/jsp/jrun__vec_new2ejspc.java:80:1:80:18: Error: No match was found for method "addElement(int)".
".
I can add it in vector but i cannot display it and if i use this to add the values in vecotr "v.addElement(u);". And then if i display the values then it shows me some thing like this "[I@2f1ad8". I hope my problem is more clear to you. Thanks again for taking pains to answer me.
abhinav
 
This will take every ounce of my mental strength! All for a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic