ArrayList for ints?

I want to have an expandible and contractible int array. I was thinking of modifying the source code of ArrayList so that rather than being exclusively for objects, it was just for int arrays. Or is there already a Class out there that handles this. I apologize in advance if the answer is very obvious.

Supp4sk1llz wrote:
If you didn't know its:
ArrayList<Integer> intArrayList = //....
That would be an example of Generics. While autoboxing maybe involved your code does not show it. A better example is:
Integer num = 5;
int x = num;
// instead of
Integer num = new Integer(5);
int x = num.intValue();

Similar Messages

  • How to implement this C code line: for ( int i = 0; i G_ReadLen; i = i + 2 )

    I want to implement the following C++ code in labview but i cannot make or loop to increase by two
    int j = 0; for ( int i = 0; i < G_ReadLen; i = i + 2 ) {
    BYTE AD_H = ByteArray.GetAt(i);
    BYTE AD_L = ByteArray.GetAt(i + 1);
    ValueArray[j] = AD_H << 8;
    ValueArray[j] = ValueArray[j] + AD_L;unsigned long Temp = ValueArray[j] >> 12; Volts[j] = ((float)ValueArray[j]) * 0.0048875;Message.Format("%X , %X - %X, -- %d, +%.3f Volts", AD_H, AD_L, ValueArray[j], ValueArray[j], Volts[j]); m_output_ep1i.InsertString(0,Message);
    j = j + 1;
    Thanks
    Solved!
    Go to Solution.

    Your code will not work.
    You are replacing elements of an empty array. A no-op in LabVIEW.
    Besides there is a lot easier way to do this:
    I just hope this is not a homework assignment.
    And for completeness sake here is Mikes solution (seen below):
    Ton
    Message Edited by TonP on 11-14-2008 12:55 PM
    Message Edited by TonP on 11-14-2008 01:03 PM
    Free Code Capture Tool! Version 2.1.3 with comments, web-upload, back-save and snippets!
    Nederlandse LabVIEW user groep www.lvug.nl
    My LabVIEW Ideas
    LabVIEW, programming like it should be!
    Attachments:
    Read as U16.png ‏2 KB

  • For (int i = listeners.length-2; i =0; i-=2) {

    Hi,
    protected void fireFooXXX() {
         // Guaranteed to return a non-null array
         Object[] listeners = listenerList.getListenerList();
         // Process the listeners last to first, notifying
         // those that are interested in this event
         for (int i = listeners.length-2; i>=0; i-=2) {
             if (listeners==FooListener.class) {
    // Lazily create the event:
    if (fooEvent == null)
    fooEvent = new FooEvent(this);
    ((FooListener)listeners[i+1]).fooXXX(fooEvent);
    Why is the listeners list traversed by 2?
    Devyn

    ^^, nm, I see now.
    Devyn

  • Blah.equals() for ints?

    I know for strings and such you sometimes have to use .equals() since they may not point to the same object but the values may be the same.
    What is the equivalent expression for ints?
    == isn't working, and if I use equals it gives the error:
    "int cannot be dereferenced"
    Edit:
    Wait a minute... if I have two int variables with the same value, I SHOULD be able to use ==, shouldn't I?????????
    Edit 2:
    Nevermind.

    String and int are completely different data types. String is an object and extends the java.lang.Object class in Java. The Object class defines the method equals() which compares references between two Objects and returns true if the references are equal. The String class overrides this method to return true if the content of the Strings being compared is the same.
    To compare int, you can very easily use '=='. Of course it works!

  • Send request for INT has no recipients(Alerts)

    Hey
    guys i m trying to configure alerts for my scenario and following Michals blog,alert waz triggered once but after that i m getting the following error "Send request for INT has no recipients".in SU01 i have given e-mail address and have admin permission,alerts are not triggered in SLG1 at all and in table SALRTTROLE,i dont see any values.
    any idea where should i start lookin?
    i have followed the troubleshootin blog too but couldn't solve
    thanx
    ahmad

    thanx Satish
    but i have gone through that thread,actually whats happening is that once i create a alert and trigger it by sending wrong data,i can see it in my alert inbox in RWB,but after that if i resend wrong data again,i dont see it,i have unchecked the "Supress multiple alerts " in Alert configuration too.
    i m getting the following warning
    Address of recipient AHMAD (INT) could not be read
    Message no. SALERT033
    Diagnosis
    The communication data for communication method INT could not be determined for recipient AHMAD.
    and after this warning in next line i get the following error
    Send request for INT has no recipients
    thanx
    ahmad
    Message was edited by:
            Ahmad

  • Dynamic Variable name (for int/long) from a String variable

    Hi,
    I want to give a int/long variable name from a String.
    for ex.
    String str = lookup + "Id";
    lookup is a String variable coming from XML. Now, for instance lookup="name". So str = "nameId".
    Now I want to create a int/long variable by nameId.
    Could anybody tell me the way how to do. Please don't tell to use MAP.
    Edited by: Shah on Dec 5, 2007 3:26 PM

    Well you can't. Use a Map.
    The compiler translates variable names into slot numbers, either within an object or withing the local "stack frame" and these slot numbers are assigned names at compile time. No new slots can be created at run time. Java is not Basic.
    Reflection allows you to find existing field names and methods (not local variables), so it's possible to map, for example, XML attribute names to field names or setters in an object but the names have to be known at compile time.

  • A & b works also for int primitives ?

    Hello
    During my lessons java SCJP 5.0 I saw that the & expression also excepts integers as oprands.
    But how can i predict the outcome of such an expression.
    For example
    int a=1,b =1;
    a++;
    System.out.println(a & b); // Prints 0
    a++;
    b++;
    System.out.println(a & b); // Prints 2
    I don't understand how Java calculates these outcomes
    How does the & work with int operands?
    thanks in advance, Auke Quist

    The error code is in the html code for the Web page and not an error you can fix.

  • Planned cost for int labour and non stockable material not visible

    Hey gurus,
    While creating an order with a material, ext service, non stock material, I am able to see the planned cost for materials in stock and ext services procured. But i'm not able to see the planned cost for non stock material and int labour. However i'm able to see the actual cost for all the items. I think I have missed some config. Please help.
    Regards,
    Abhishek

    Hi,
    As said by Pithan there is a problem in costing variant for planned cost which you have assigned to prder type at plant level.
    Problem underlies within valuation variant assigned to costing variant.PM01 is your costing variant here.Check diiferent heads within valuation variant for this costing variant.There under activities tab what is calculation parameter you have selected.If it is blank you will not get any internal activity cost.You need to select at least one from dropdown like cost from previous period or avaerage cost etc.Then you will get planned cost for internal activities.SAmething applies to non stock material.
    Check in OKP6 for all these and make sure that you have selected at least one cost calculation schema there for activities and material and external.
    Regds,
    atul

  • Are i++, i-- atomic and thread safe for int i

    I want to minimize the sync time multiple threads take to contend for a shared pool, which is implemented as a FIFO. My plan is to:
    1. Use a int variable "count" to trace the free obj count. Hence eliminates the need of synchonized methods size() and isEmpty()
    2. Increment & decrement count when implemeting push() and pop()
    3. Minimize the number of statements in synchonized block as possible within push() and pop(), which in this case, excludes count++ and count-- provided these operations are atomic and thread safe
    Have I lost something ?

    So, may I make a conclusion.
    To minimize contention, I use FIFO instead LIFO or stack and build it from scratch without extending from existing Collection-related class
    1 public class FIFO {
    2 . . private volatile int count;
    3 . . private Object head, tail;
    4 . . public Object pop() {
    5 . . . .synchonized (tail) {
    6 . . . . .if (count >= 3) {
    7 . . . . . .Object tail_origin = tail;
    8 . . . . . .// Re-organizing the linked list skipped
    9 . . . . . .synchonized (this) {
    10 . . . . . . count--;
    11 . . . . . }
    12 . . . . . return tail_origin;
    13 . . . . }
    14 . . . . else {
    15 . . . . . throw new PoolEmptyException();
    16 . . . . }
    17 . . . }
    18 . . }
    19 . . public void push(Object o) {
    20 . . . synchronized (head) {
    21 . . . . . // Re-organizing the linked list skipped
    22 . . . . . head = o;
    23 . . . . . synchonized (this) {
    24 . . . . . . count++;
    25 . . . . . }
    26 . . . }
    27 . . }
    28 . . public int sizeOf() {
    29 . . . return count;
    30 . . }
    31 }
    1. The reason I choose FIFO is to avoid the contention between push() and pop() -- they are NOT declared as synchonized, instead they only lock head and tail respectively. (Sorry I borrow the name push and pop from stack)
    2. pop() only works when count >= 3 to avoid head == tail after pop() and hence a further call to push() block concurrent call to pop() and vice versa (see line 5 and 20)
    3. The goal is to minimize the time and scope of contention. In line 9 and 23, I lock the whole pool object only when modify count, which is not atomic.
    4. This pool is used for a thread pool supporting many concurrent short-lived HTTP request
    Have I missed something ?
    Thanks a lot!

  • Overriding compareTo method for ints

    I'm having a problem writing the overloaded compareTo method for my class. Ideally, the class will be used in collections, and has to be sorted by an int value. I've found a messy way to do this by converting the int values into strings, then comparing those, but I would like to know if there is a better way to do this.

    You could subtract, unless you are worried about over/underflow.
    Then you can just compare the ints the old-fashioned way:
    import java.util.*;
    public class Test implements Comparable<Test> {
        int x;
        public int compareTo(Test that) {
            return this.x - that.x;
            //return this.x < that.x ? -1 : this.x > that.x ? 1 : 0;
    }

  • XMLEncoder - how to stop it from using NaN for int's

    I am trying to invoke a webservice. I used the Flex Builder 3
    service code generator. I have an object "Person" which has three
    fields: {id:int, firstName:String, lastName:String}
    I have a case where I invoke a method on a webservice that
    takes a person object. the person object in this case should only
    have a first and last name defined (no id, yet). I stepped through
    the flex source code to see what happens and basically when it
    encodes the Person object it gets to the "id" field whose value is
    NaN (b/c I never set it). The encoder eventually just decides that
    (NaN >= integer.min value) and passes it along so it gets into
    my SOAP message as <id>NaN</id>. This causes problems
    at the web service (java) side b/c it doesn't know how to
    unmarshall "NaN".
    So...any suggestions on how to prevent it from sending
    <id>NaN</id>. maybe even just <id /> would be
    ok.

    Moving the iOS device backup location
    Open a command prompt by hitting the start button and typing CMD<Enter> in the search box that opens up, or with Start > Run on older Windows.
    To move the current backup folder from C: to D: (for example) type in this command and press <Enter>
    Move "C:\Users\<User>\AppData\Local\Apple Computer\MobileSync\Backup" "D:\Backup"
    Where <User> is your Windows user name.
    To make iTunes look for the data in the new location type in this command and press <Enter>
    MkLink /J "C:\Users\<User>\AppData\Local\Apple Computer\MobileSync\Backup" "D:\Backup"
    If your preferred drive has a different letter or you already have a folder called "Backup" then edit "D:\Backup" accordingly in both commands.
    If you have Windows XP then you'll need a third-party tool such as Junction to link the two locations together instead of the MkLink command. The source folder is C:\Documents and Settings\<User>\Application Data\Apple Computer\MobileSync\Backup
    I'm pretty sure the same technique will work with the iPod software download folder, although it is worth noting that it does not work inside the iTunes Media folder. At last time of testing if you attempt to redirect sections of the media folder and iTunes writes to a redirected location it will erase the link and replace it with a regular folder.
    tt2

  • Sort arrayList for integer

    hi,
    some doubts on the syntax
    rows.add(String.valueOf(destList));is this the correct syntax eventhough my "destList" is an integer?
    Collections.sort(rows);i would like to sort my arrayList but it doesnt seem to work with this syntax.the values in my arraylist are in integer.
    please help.thanks

    Maybe a little off topic, but this might be of interest to anyone that wants to sort a 2 dim object array (Object[][]).
    As part of the formatteddataset open source API I have a utility class called ArraySQL. It allows you to issue a reduced sql syntax against an array (i.e. specify a column list, where and order by clauses). The basic idea is that because a 2 dim Array is conceptually similar to a db table you could be able to query it. I will be releasing on sourceforge in a couple weeks, but in the meantime if anyone is interested i can send it to them. Here are some examples
    import com.fdsapi.arrays.ArraySQL;
    Object[][] data{
          {"jim","smith", new Integer(200)}, 
          {"jeff","souza", new Integer(500)},
          {"jim","anderson", new Integer(100)},
          {"stan","jones",new Integer(2000)}};
    ArraySQL asql=new ArraySQL("select * from array where col0 in ('jim', 'jeff') order by col0 asc, col1 desc")
    Object[][] newData=asql.execute(data);
    asql=new ("select * from array order by col2 desc");
    newData=asql.execute(data);steve -
    http://www.fdsapi.com - An easy, fast, extensible way of generating xml and html
    http://www.jamonapi.com - An easy way to monitor application code.
    Both tools are open source and available for download on the given sites.

  • ObjectiveC - does retain/assign/copy matter when defining a setter for int?

    I'm defining a custom class in Objective C. My interface has an integer instance variable. I have declared a @property for this instance var and I have also declared @synthesize for it in the implementation. However, I need to create a custom setter accessor for this int value. Should I bother trying to retain/release in this setter or does the retain/release behavior only apply for object instance vars?
    e.g.:
    -(void)setFoo:(int)newValue {
    // check to see if newValue is permitted...
    if (foo != newValue) {
    [foo release];
    foo = newValue;
    or just this:
    -(void)setFoo:(int)newValue {
    // check to make sure newValue is ok....
    foo = newValue;
    NOTE: the darn forum is turning my brackets into formatting...please use your imagination
    Message was edited by: sneakyimp

    sneakyimp wrote:
    does the retain/release behavior only apply for object instance vars?
    Yes, you should only send retain or release (or any other message for that matter) to an object. For C type instance vars, you should use the assign attribute when declaring a property. E.g.:
    @property (nonatomic, assign) int nCount;
    -(void)setFoo:(int)newValue {
    foo = newValue;
    The above is correct. If you declare a foo property with the assign attribute and @synthesize foo, I think the compiler will generate that same setter for you.
    To format code here just place a tag before and after:
    Paste your code here.
    Note that isn't an xml tag, so the begin and end tags are identical. To see how your post will appear, click the Preview tab above the Reply editor panel.

  • Null value for int and datetime date type in xml schema

    hi:
    I am embarrassed by a qustion in xml schema; i defined a xml schema file like
    this:
    <elementFormDefault="qualified" attributeFormDefault="qualified">
    <xs:element name="test">
    <xs:annotation>
    <xs:documentation>Comment describing your root element</xs:documentation>
    </xs:annotation>
    <xs:complexType>
    <xs:sequence>
    <xs:element name="name" type="xs:string"/>
    <xs:element name="password" type="xs:string" nillable="true"/>
    <xs:element name="user" type="xs:int" nillable="true"/>
    <xs:element name="s_time" type="xs:dateTime"/>
    </xs:sequence>
    </xs:complexType>
    </xs:element>
    </xs:schema>
    and I send this file to workflow clientrequest() node, I wanted to receive data
    in this schema file.but when i send null value to the element "user" and "s_time"
    in workshop test tool(test soap),and use function in xmlbean like isNilUser or
    isNilStime, one error occur.
    I don't kown why, I had to ask the engineer of bea in china, one told me a bug.
    is that true?

    Visakh16 I cant agree more with you on it, it is good but in production u cant have them change maxrows. I think
    Patrick  Hurst is a better option. debug the package have it running and move up
    Please mark as helpful and propose as answer if you find this as correct!!! Thanks,Dia Agha .
    Hmm..Why do you need to change it in production?
    What I suggested was to tweak the setting in dev machine so that it interprets the Excel file datatypes correctly when doing development. Once mapping is set correctly then it will work fine when in production or in any other environment. The tweaking is
    just to make sure it interprets the datatype correctly at design time and has nothing to do with production deployment 
    Please Mark This As Answer if it solved your issue
    Please Mark This As Helpful if it helps to solve your issue
    Visakh
    My MSDN Page
    My Personal Blog
    My Facebook Page

  • BOE 3.1 SR3 on Solaris SPARC - how to for Int kit for SAP Solutions ?

    Hi,
    this is my first BOE installation and I've just installed the BOE SR3 Enterprise Server on Solaris SPARC with SAP WAS 7.0 and Oracle 11.2.0.2 providing the CMS database location and the Java application server for the BOE applications.
    The installation went ok and all BOE Server services are running. I've now got to install the XI 3.1 SR3 BOBJ Integration for SAP Solutions kit and have read the installation and administration guide for this.
    The pre-requisites state that the SAP RFC & Java Connector needs to be put in place before deploying. Are these not part of the NW 7 WAS 7.0 Java Server anyway ?
    If anyone has any pointers to more detailed instructions for doing Integration for SAP solutions kit other than the guide then please let me know.
    Regards,
    Brian.

    Hello Ingo,
    many thanks for your reply, although I'm still confused. My Business Objects 3.1 Enterprise Server runs on the same host as a NW 7 WAS and has it's applications deployed and running on the NW 7 WAS Java instance .According to OSS 549268 you should not use the standalone SAP JCO connector if your applications are running on a SAP WAS - it has it's own integrated SAP Java Connector
    "SAP JCo is available for two different environments: there is the standalone version and the version integrated in the SAP J2EE Engine. These two JCo variants have a compatible API but are implemented differently, so you may not mix them together within one environment.
    SAP JCo 2.1 is the standalone version and can be used in all Java applications not running in an SAP J2EE Engine environment.
    So it seems I don't need to use the standalone Java connector ?
    Regards,
    Brian.

Maybe you are looking for