Add a double to a Vector?
How does one add a double to a vector?
Many thanks in advance
has implementations identical to java's collections
which allow primative types.
atleast this was good before 1.5This is true:
OP, if you are running 1.5+ you can do:
someVector.add(1.0);
Similar Messages
-
Use addElement to add a double to a vector
Hi
I've defined a vector, and am adding elements to it. All elements are of type String, except for GPA, which is of type double. When I enter this code into Eclipse:
Vector row = new Vector();
row.addElement(aStudent.getID());
row.addElement(aStudent.getName());
row.addElement(aStudent.getPhoneNumber());
row.addElement(aStudent.getGPA());
row.addElement(aStudent.getMajor());
I get an error on the next to last line (containing the getGPA call). The error is "The method addElement(Object) in the type Vector is not applicable for the arguments (double)". I thought I could add anything to a vector, so I'm not sure what the problem is.
What am I missing?
Thanks very much for the help!
tlYou can only add objects (e.g. Double), not primitives (e.g. double) to a Collection (e.g. Vector).
row.add(new Double(aStudent.getGPA()));You may have noticed I used add() rather than addElement(). There aren't many good reasons not to use the Collection/List methods with Vectors. There really aren't many good reasons to use Vector in this case... -
Not able to add a double to a vector?
Anyone have any idea why the line below would result in Eclipse telling me that the method vector.addElement(Object arg0) wouldn't accept a double as an argument?
tempVec.addElement(Double.parseDouble(cellContents));Anyone have any idea why the line below would result
in Eclipse telling me that the method
vector.addElement(Object arg0) wouldn't accept a
double as an argument?
tempVec.addElement(Double.parseDouble(cellConten
ts));
Because Double.parseDouble returns a primitive, not a reference. -
How to add the double headings in Alv Report.
Hi All,
Plz suggest me how to add the double headings in ALv Report.
RamHi,
Try out this program....
REPORT ypm_historycard_rep.
TYPE-POOLS : slis.
DATA : it_cbm TYPE STANDARD TABLE OF mara.
DATA : it_layout TYPE STANDARD TABLE OF slis_layout_alv WITH HEADER LINE,
wa_fcat TYPE slis_fieldcat_alv,
it_fcat TYPE slis_t_fieldcat_alv.
START-OF-SELECTION.
SELECT *
FROM mara
INTO CORRESPONDING FIELDS OF TABLE it_cbm
where matnr = 'D80K7'.
END-OF-SELECTION.
it_layout-zebra = 'X'.
it_layout-colwidth_optimize = 'X'.
it_layout-f2code = '&ETA'.
APPEND it_layout.
DEFINE macro4fcat.
wa_fcat-col_pos = &1.
wa_fcat-fieldname = &2.
wa_fcat-tabname = &3.
wa_fcat-seltext_l = &4.
append wa_fcat to it_fcat.
clear wa_fcat.
END-OF-DEFINITION.
macro4fcat '1' 'MATNR' 'IT_CBM' 'MATERIAL NO' .
DESCRIBE TABLE it_cbm.
IF sy-ucomm = '&F03'.
MESSAGE 'hi hello good morning "press enter button" this is quiz' TYPE 'S'.
ENDIF.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = sy-repid
i_callback_html_top_of_page = 'HTML_TOP_OF_PAGE'
is_layout = it_layout
it_fieldcat = it_fcat
i_save = 'A'
TABLES
t_outtab = it_cbm
EXCEPTIONS
program_error = 1
OTHERS = 2
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
*& Form html_top_of_page
* text
* -->TOP text
FORM html_top_of_page USING top TYPE REF TO cl_dd_document.
DATA: l_text(255) TYPE c.
DATA: text1(255) TYPE c.
DATA: t_header TYPE REF TO cl_dd_table_element ,
wa_header TYPE REF TO cl_dd_table_area.
CALL METHOD top->add_gap
EXPORTING
width = 10.
CALL METHOD top->add_text
EXPORTING
text = 'hello'
sap_style = 'HEADING'
CALL METHOD top->add_gap
EXPORTING
width = 20.
CALL METHOD top->add_text
EXPORTING
text = 'HOW ARE YOU'
sap_style = 'HEADING'.
CALL METHOD TOP->new_line
* EXPORTING
* repeat =
CALL METHOD top->add_gap
EXPORTING
width = 50.
CALL METHOD top->add_text
EXPORTING
text = '____________________________________________________________'
sap_style = 'HEADING'.
CALL METHOD TOP->new_line
* EXPORTING
* repeat =
CALL METHOD top->add_gap
EXPORTING
width = 90.
CALL METHOD top->add_text
EXPORTING
text = 'YOU CAN TRY LIKE THIS'
sap_style = 'HEADING'.
ENDFORM. "html_top_of_page
Regards
Debarshi -
URGENT! Sorting double value in Vector
Suppose VaggCost is a Vector store something like [752.5467, 834.4564, 1000.567, 65.5767]
The following codes have error after sortAggCost(), CAN YOU GIVE ME A HAND???
I am using JDK 1.4.1, Sun ONE Studio Update 1
Thanks,
David
public void sortAggCost(Vector VaggCost){
for(int p = 1; p < supplierCount; p++){
double keyValue = ((Double)(VaggCost.elementAt(p))).doubleValue();
int j = p;
for(; j > 0 && keyValue < ((Double)(VaggCost.elementAt(j-1))).doubleValue(); j--)
VaggCost.setElementAt(VaggCost.elementAt(j-1), j);
} // End of second For loop
VaggCost.setElementAt(keyValue +"", j);
} // End of first For loopIs that really a vector of Doubles, or a Vector of Strings representing Doubles?
Collections.sort() will sort a vector of Doubles correctly.
If you actually have a Vector of Strings representing doubles, you'll have to do something else. Java won't automatically convert from one to the other, like, say, Perl.
One option would be to use the two-arg version of Collections.sort(), and define a class for the second arg. See the docs. -
Why can't I add an Object[] to a Vector ? super Object[] ?
I don't understand why javac rejects these two statements:
Vector<? super Object[]> v= new Vector<Object[]>();
v.add(new Object[0]);cannot find symbol
symbol : method add(java.lang.Object[])
location: class java.util.Vector<capture of ? super java.lang.Object[]>
v.add(new Object[0]);
^
The type of v can only be one of these 4:
Vector<Object[]>, Vector<Object>, Vector<Serializable>, Vector<Cloneable>.
Therefore, I should always be allowed to add an Object[] to it, right?
The following example is very similar, but this one is accepted by javac.
Vector<? super Number> v= new Vector<Number>();
v.add(42);I didn't find a relevant difference to the first example, nor something in JLS3 that would forbid it. Is this a javac bug?There is a difference between legal and practical. Practical is a matter of opinion. I thought I should try the combinations to see which make sense.
I don't find it intuative that list.add(list.get(0)) should fail to compile.
While the definitions have a logic of their own, some are very hard to put it into english exactly what they really mean. This means finding a practical purpose for them even harder.
For example List<? super Object>
add(x) is legal for non-arrays
method(list) is illegal for method(List<Object>) but is legal for method(List<? super Object[]>)
public class A {
public static void foo(List<? super Object[]> l) { }
public static void foo2(List<Object[]> l) { }
public static void foo3(List<? extends Object[]> l) { }
public static void bar(List<? super Object> l) { }
public static void bar2(List<Object> l) { }
public static void bar3(List<? extends Object> l) { }
public static void bar4(List<?> l) { }
public static void main(String[] args) {
{ // can be { Object, Object[] }
List<? super Object[]> l = new ArrayList<Object[]>();
l.add(l.get(0)); // illegal
l.add((Object) null); // illegal
l.add((Integer) null); // illegal
l.add((Object []) null); // illegal
l.add((Integer []) null); // illegal
l.add((Integer [][]) null); // illegal
foo(l); // List<? super Object[]> - legal
foo2(l); // List<Object[]> - illegal
foo3(l); // List<? extends Object[]> - illegal
bar(l); // List<? super Object> - illegal
bar2(l); // List<Object> - illegal
bar3(l); // List<? extends Object> - legal
bar4(l); // List<?> - legal
{ // can be Object[] or (? extends Object)[]
List<Object[]> l = new ArrayList<Object[]>();
l.add(l.get(0)); // legal
l.add((Object) null); // illegal
l.add((Integer) null); // illegal
l.add((Object []) null); // legal
l.add((Integer []) null); // legal
l.add((Integer [][]) null); // legal
foo(l); // List<? super Object[]> - legal
foo2(l); // List<Object[]> - legal
foo3(l); // List<? extends Object[]> - legal
bar(l); // List<? super Object> - illegal
bar2(l); // List<Object> - illegal
bar3(l); // List<? extends Object> - legal
bar4(l); // List<?> - legal
{ // Only allows wildcards, Object is illegal.
List<? extends Object[]> l = new ArrayList<Object[]>();
l.add(l.get(0)); // illegal
l.add((Object) null); // illegal
l.add((Integer) null); // illegal
l.add((Object []) null); // illegal
l.add((Integer []) null); // illegal
l.add((Integer [][]) null); // illegal
foo(l); // List<? super Object[]> - illegal
foo2(l); // List<Object[]> - illegal
foo3(l); // List<? extends Object[]> - legal
bar(l); // List<? super Object> - illegal
bar2(l); // List<Object> - illegal
bar3(l); // List<? extends Object> - legal
bar4(l); // List<?> - legal
{ // can add non-arrays but can only match ? super Object, ? super Object[], or ? extends Object, but not Object
List<? super Object> l = new ArrayList<Object>();
l.add(l.get(0)); // legal
l.add((Object) null); // legal
l.add((Integer) null); // legal
l.add((Object []) null); // illegal
l.add((Integer []) null); // illegal
l.add((Integer [][]) null); // illegal
foo(l); // legal
foo2(l); // illegal
foo3(l); // illegal
bar(l); // legal
bar2(l); // illegal
bar3(l); // legal
bar4(l); // legal
{ // can add array but cannot call a method which expects an array. 100% !
List<Object> l = new ArrayList<Object>();
l.get(0).toString();
l.add(l.get(0)); // legal
l.add((Object) null); // legal
l.add((Integer) null); // legal
l.add((Object []) null); // legal
l.add((Integer []) null); // legal
l.add((Integer [][]) null); // legal
foo(l); // legal
foo2(l); // illegal
foo3(l); // illegal
bar(l); // legal
bar2(l); // legal
bar3(l); // legal
bar4(l); // legal
{ // cannot add any type but can match ? or ? extends Object.
List<? extends Object> l = new ArrayList<Object>();
l.add(l.get(0)); // illegal
l.add((Object) null); // illegal
l.add((Integer) null); // illegal
l.add((Object []) null); // illegal
l.add((Integer []) null); // illegal
l.add((Integer [][]) null); // illegal
foo(l); // List<? super Object[]> - illegal
foo2(l); // List<Object[]> - illegal
foo3(l); // List<? extends Object[]> - illegal
bar(l); // List<? super Object> - illegal
bar2(l); // List<Object> - illegal
bar3(l); // List<? extends Object> - legal
bar4(l); // List<?> - legal
{ // same as ? extends Object.
List<?> l = new ArrayList<Object>();
l.add(l.get(0)); // illegal
l.add((Object) null); // illegal
l.add((Integer) null); // illegal
l.add((Object []) null); // illegal
l.add((Integer []) null); // illegal
l.add((Integer [][]) null); // illegal
foo(l); // List<? super Object[]> - illegal
foo2(l); // List<Object[]> - illegal
foo3(l); // List<? extends Object[]> - illegal
bar(l); // List<? super Object> - illegal
bar2(l); // List<Object> - illegal
bar3(l); // List<? extends Object> - legal
bar4(l); // List<?> - legal
} -
Easiest way to add a double stroke to text / or object in Illustrator 10
New to the forum and wondered if someone can help me find a solution in adding a double stroke to text or an object? I have illustrator 10 (Mac). Thanks Also, should I be in a different forum section or is this correct?
Go to window/appearance and add as many strokes and fills you want, and reorder as you need
here you can see a movie on how it works, no matter the video is in AiCS3, works the same in Ai10.
http://www.adobe.com/designcenter/video_workshop/
look under de illustrator product "Using the appearance panel and efects"
http://marizmendi.googlepages.com/index33 -
How To Add the Double Quotation Marks Around a String
In the statement below, the recipientField.getEmailAddress() give me an e-mail address:
theEmailAddressList.add( recipientField.getEmailAddress() );The e-mail address has to be wrapped within a pair of double quotation marks. Therefore, I have to do the concatenation. Do I wrap each double quotation mark with a pair of single quotation marks?
theEmailAddressList.add( '"' + recipientField.getEmailAddress() + '"' );I do not understand.
I am asking if the statement below does what I intend to do:
theEmailAddressList.add( '"' + recipientField.getEmailAddress() + '"' ); -
How can I add all elements in a Vector to a TextArea?
I am trying to add Items in a vector to a Text area.
I am trying to get the outcome to look something like this:
where each line is a new stack???
-------NP--------v--------p-------det---PP
---det-------NP-------v------p------det-----PP
-det------NP--------v---------p------det-----p------NP
det---adj-----NP-------v--------p------det-----p------NP
det---adj------n-------v--------p------det-----p-------n
a-----big-----dog-----rode-----with-----a-----old-----woman
thanks, stevenRead through the vector and append its elements to the text area. Here's a skeleton code, I'll leave the formatting to you (since I don't understand what you wrote):Enumeration e = theVector.elements();
while (e.hasMoreElements()) {
theTextArea.append(e.nextElement().toString());
} -
How to add custom pattern to your vector artwork
Hi Everyone,
I'm hoping you can help me with the following question.
Please see attachment - I'm interested to know how you can add a custom pattern (in this case a geometric design) across the artwork as a whole?
If you take a closer look, you can see how the geometric pattern is making up on all different colours of the image including the stars
How do you do this? I'm really stuck
regards,
HashHi Monika,
Sounds simple enough - thanks -
How to add the resultant value in a double
Hay guys
I am adding two vectors (each vector has 3000 values). I want to add them together and store in a double variable. But when i compile i have an error. (incompatible type found, Object required.)
How can i store the values of two vector in an object
here is my peice of code
public void result (){
double temp1;
for(int i=0; i<= 3000;i++){
temp1 = (double)v.elementAt(i) + (double)v1.elementAt(i);
NOTE: i already have 3000 values (or objects) in my vectors
Thanks alot in advanceOkay guss. i Used (Double) in my vectors as object because with lowercase (double) it throws error. Asbestos you said (What are the objects in the vectors? Are they Doubles (with a capital 'D')? If so, use the methods found in the Double API to change the Doubles into doubles, instead of trying to cast them.) i tried but i didnt able to findout how to use that API. Can anybody show me
Here is my full code.
public class Simple {
public long c=0;
public long a = 16807;
public long m = 2147483647;
public long XO = 238640;
public long XO1 = 248921;
public Vector v = new Vector();
public Vector v1 = new Vector();
public Vector vLast = new Vector();
public double x = 0, R = 0;
public double LCDx (){
for(int i=0; i<= 3000;i++){
x = (((a)*(XO))+c)%m;
R = x/m;
XO = (long)x;
v.addElement(new Double(R));
System.out.println(i+" Value: "+R);
return R;
public double LCDy (){
for(int i=0; i<= 3000;i++){
x = (((a)*(XO1))+c)%m;
R = x/m;
XO1 = (long)x;
v1.addElement(new Double(R));
return R;
public void result (){
double temp1;
for(int i=0; i<= 3000;i++){
// PROBLEM PART
double temp = (double)v.elementAt(i) + (double)v1.elementAt(i);
vLast.add(temp);
}Thanks alot in advnacee -
Vector allow double values ?
Hai,
I m new to java..
I want to add double values in vector. But i came to know that Vector allow only String. Is it true or not ? if yes how ?
Please give me idea how add double values in vector directly
Regards
MerlinaHai,
I m new to java..
I want to add double values in vector. But i came to
know that Vector allow only String. Is it true or not
? if yes how ?
Please give me idea how add double values in vector
directly
Regards
MerlinaNo, vectors allow Objects.
So Vectors will allow Double, but not double.
On the other hand, in Java 1.5, you have autoboxing that will make it LOOK like you can use doubles.
Also, since you're looking into Vector, I HIGHLY recommend looking into ArrayList, instead.
- Adam -
Vectors : Converting to double[ ] array
Hello,
I have a vector which I know consists of double values only. I am trying to create an array of double from this vector but am having some difficulty.
Firstly if I try this :
double[] high = (double[])datavector.high.toArray(new double[0]);JBuilder reports :
'Cannot find method toArray(double[])'
But if I try this :
Double[] high = (Double[])datavector.high.toArray(new Double[0]);It works.
So from this I assume 'Double' is not equal to 'double'
The trouble is I require 'double[ ]' and NOT 'Double [ ]'.
Casting Double as (double) does not work... so how do I get double[] from my original vector ?
Many thanks
Kerrydouble[] d = new double[v.size()];
int i = 0;
for(Iterator<Double> it = v.iterator(); it.hasNext();)
d[i++] = (double)it.next();
just declare the double array to be the size of the vector, then loop thru and populate the array one at a time
~Tim -
Autoboxing does not work in Vector.add(x) context?
Hello,
I wondered about this bit of code today:
Vector<Long> data = new Vector<Long>();
long l = 10;
data.add(l);On the add method I get the error message "The method add(Long) in the type Vector<Long> is not applicable for the arguments (long)"... I mean, isn't this what autoboxing was meant for? I still have to use data.add(new Long(l)); to get it to work.
Casting to Long, such as add((Long)l) doesn't work either, though it explicitly tells the compiler that we expect an object here (as if this were necessary...)
Now, who is getting it wrong - me or the compiler? ;-) I am using the JDK 1.5.0, of course, and the Eclipse 3.1 IDE; maybe it's a problem of the IDE also.
Thanks for answers,
kind regards, LeoThanks for the reply.
It seems that the Eclipse parser does not fully support autoboxing.
Concerning the confusing variable name: this is not a live code snippet, but a made-up example.
Greetings, Leo -
How to add double stroke to text or an object?
I have illustrator 10 (MAC). Wondering the easiest way to add a double stroke to text or an object? Also, how can I move the stroke so its not necessarily on the outside of text? Was thinking more of an outline with separation between the two colors on the double stroke. Thanks
I'm not really an expert in user-land Illustrator so I'm not always up-to-speed on the terminology -- what do you mean by 'double stroke'?
Assuming you're talking about doing this in code, I *might* be able to help you on this but it's been a couple of years since I used the pre-CS text engine. I'd be more likely to be able to help you if this was CS+, but I can try.
If you're talking about doing it through the GUI as a user, I'm the last guy you want to ask :)
Maybe you are looking for
-
Trying to update Project scheduled finish date - newbie help needed!
Guys, I am super new to Oracle Projects, I have never used it before. I've just learned a few things in the UI and read through the docs documenting the stored procs. My question is simple (hopefully) In the UI I choose a responsibility, then und
-
BAPI_DOCUMENT_CHECKOUTVIEW in background
Hello, I want to copy an original file from a document info record to a server. I tried to use BAPI_DOCUMENT_CHECKOUTVIEW. (I also tried BAPI_DOCUMENT_CHECKOUTVIEW2 and CV120_DOC_CHECKOUT_VIEW.) I use the BAPI in a workflow. When i call the workflow
-
Reader 9.3 locks up when using icons to move within doc & print
I've run into an issue with Adobe Reader 9.3.2 under XP SP3 all updated... When I try and read a PDF and move through the documents using the various icons at the top menu - such as the arrows or printing icon - it hangs up. If I use the slider bar
-
5G iPod Takes 10-15 minutes to unmount/boot
After I sync my 5G iPod and iTunes says it's OK to disconnect,I unmount (eject) my iPod from iTunes. However, it takes approximately 12 to 13 minutes before my iPod's hard drive stops spinning and the Do Not Disconnect message is replaced by the iPod
-
Workflow integration with IHS ?
Hi Experts, We have a specific requirement to create the sap sap workflows from the IHS risk analysis. The deviation in the risk should trigger the workflow as a followup action.There is no standard object in ehs for this,as per my understanding. Doe