Leading zero is kept in arraylist ---

Hello,
Running the program below should remove all zeros from an arraylist; yet, the leading zero still appears in the output. Any explanation would be most helpful ... Thanks
import java.util.ArrayList;
public class Example
public static ArrayList<Integer> nums = new ArrayList<Integer>();
public static void numQuest()
int k = 0;
Integer zero = new Integer(0);
nums.add(0);
nums.add(0);
nums.add(4);
nums.add(2);
nums.add(5);
nums.add(0);
nums.add(3);
nums.add(0);
while ( k < nums.size())
if (nums.get(k).equals(zero))
nums.remove(k);
k++;
System.out.print("contents of nums: " + nums );
System.out.print("\n");
public static void main (String[] args)
numQuest();

import java.util.*;
public class Example {
    public static void main (String[] args) {
        List<Integer> numbers = new ArrayList<Integer>();
        Collections.addAll(numbers, 0, 0, 4, 2, 5, 0, 3, 0);
        System.out.println("before: " + numbers);
        numbers.removeAll(Arrays.asList(0));
        System.out.println("after: " + numbers);
}looping over a collection while removing elements (which shifts the rest up) is a bad idea, unless you are going backwards from end to beginning.
But using removeAll is even easier!
The manual solution is to use an iterator and its remove method:
import java.util.*;
public class Example {
    public static void main (String[] args) {
        List<Integer> numbers = new ArrayList<Integer>();
        Collections.addAll(numbers, 0, 0, 4, 2, 5, 0, 3, 0);
        System.out.println("before: " + numbers);
        for(Iterator<Integer> i = numbers.iterator(); i.hasNext(); ) {
            if (i.next().equals(0)) {
                i.remove();
        System.out.println("after: " + numbers);
}

Similar Messages

  • Removing leading zeros and leading blank spaces from an input field

    Hi All,
    I have an input field which is alphanumeric and i need to remove the leading zeros and blank spaces in it , but intermediate spaces should be kept .
    so i used the UDF
            String output = input.replaceFirst("^0+","");
            return output;
    but this code does not remove the leading blank spaces . Can anybody help in modifying this code so that even the leading blank spaces along with leading zeros  can be removed .
    Regards ,
    Loveena .

    lets say input is a
    then
    int len = a.length();
    for(int i;i< length;i++)
    if(a.substring(0,1).equals(" ") || a.substring(0,1).equals("0"))
    a = a.substring(1,len);
    return a;
    hope you got the logic so that you can enhance it better

  • Exporting Numbers file with leading zeros as csv file

    When I export a list of mobile phone numbers with leading zeros (086* etc.) from Numbers as a csv file, the leading zeros are stripped out, although the cells are previously formatted as text. What can I do about this?

    "When I export a list of mobile phone numbers with leading zeros (086* etc.) from Numbers as a csv file, the leading zeros are stripped out, although the cells are previously formatted as text. What can I do about this?"
    Well, the first thing you could do would be to post your question in one of the forums for Numbers.
    Click Discussions to get to the Discussions index page, then the section for the version of iWork you're using, then the Numbers forum in that section.
    In AppleWorks (which doesn't offer an opportunity to Save as or Export as csv) I'd force the application to see the phone numbers as text by inserting some non-numeric characters into the string of digits.
    Examples: 000-123-4567, 000 123 4567
    It may also be a function of the application you are using to open the csv file.
    When I did a brief test of the suggestion above with Numbers '09, I got this result on opening the file in Text Edit:
    ,1234567890,num
    ,123-456-7890,tex
    ,0123456789,num
    ,012-345-6789,tex
    ,0001234567,num
    ,000-123-4567,tex
    Note that both the examples entered as a string of digits only (num) and those entered with inserted hyphens (tex) kept the leading zeroes. Cell format for the column containing the phone numbers was set to Text.
    Regards,
    Barry

  • Can Lightroom use leading zeroes?

    My file naming convention is 3-digit with leading zeroes. This allows the files to naturally sort in the correct order. I cannot stand to see a list of files such as: 1, 10, 11, 12, 2, 21, 22, 23, etc.
    This is such a simple thing, but I don't seem to be able to get LR to do this for me. Bridge will do it... Hm-m-m-m-m.
    Oh. I'm on a Mac G4 Powerbook, CS3 upgrade and LR.
    Thanks,
    Kittie

    I don't keep the files I export or import them back into LR. I exported from an ordered collection and renamed them so they would "float" in order alphabetically for a slide show.
    If you are going to be using LR, won't you want to move your photos from iview? Why don't you post another question about iview. There must be people here who have converted from it. First, try a search of this forum for iview.
    I've found that if there is a photo taken within the same second, LR adds something, I think a -1 to the name.
    Metadata. There are some things written, even entire books on DAM (Digital Asset Management). I've had some experience cataloging my photos in other products so I kind of knew what I wanted to do in LR. Think through how you will want to view your photos, what you will want to search on, etc.
    For example, me. We do a lot of traveling. I want to be able to find all photos from a particular trip. I do folder by trip, so that works so I wanted a program that supported my own folder organization, which LR does. But folders don't identify a photo if it gets out of its folder, so I chose an IPTC tag to use to identify them. I chose Job Identifier after reading about the tags and what they are usually used for.
    Non-travel photos are foldered by date, mostly. So to find a picture of a particular flower or a particular person, I will need keywords. I also like the fact that you can order or find things by capture date in LR. That's because we are old and we have lots of photos from long long ago.
    I use all of the location fields. "location", city, state, country. I use "location" for let's say Grand Canyon National Park, which isn't in a city. Someone else noted here that they put something like that in city because it isn't in a city and it means you don't have to look two places for the "top layer" of that sequence of country, state, city/location. I think that's a good idea, but I'd already started, so I kept what I was doing.
    Some references from my notes.
    http://www.iptc.org/IPTC4XMP/
    http://www.controlledvocabulary.com/imagedatabases/iptc_core_mapped.pdf
    http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/IPTC.html
    http://www.ap.org/apserver/userguide/codes.htm
    http://www.dartmouth.edu/comp/about/projects/digitalmedia/images/resources/metadata-schema s.html

  • Keeping leading zero of an integer

    Wondering if anyone can help me solve this small problem.
    Here's what I had:
    for(int i=01; i<13; i++) {
       String month = "2003" + i;
       System.out.println(month);
    }This gives me the following output:
    20031
    20032
    20033
    20034
    20035
    20036
    20037
    20038
    20039
    200310
    200311
    200312
    However, I want the output to be:
    200301
    200302
    200303
    200304
    200305
    200306
    200307
    200308
    200309
    200310
    200311
    200312
    Then I tried this:
    String year = "2003";
    String month = new String()
    for(int i=01; i<13; i++) {
       if(i<10)
          month = year+"0"+i;
       else
          month = year+i;
       System.out.println(month);
    }The code above gives me the results I want. However, I'm thinking that there has to be a better way to do this. Is there anyway to increment the variable i and kept it two digits? I mean keeping the leading zero until it gets to the number 10? Any ideas?

    the previous poster is right. It's also a little odd how you have things setup, in that you're expressing dates with an unusual approach (most people would use Date or Calendar), but, if you want to keep like you have it, I think this might be the easiest solution:
    int date = 200300;
    for (int i = 1; i < 13; i++ ) {
      System.out.println(date + i);
    }

  • Adding leading zeros in abap objects.

    Can anyone explain me
    1. How to add leading zeros to a field in abap objects.
    For eg:
    data: dmb(6) type c value '123456',
    actually the output value of c should have leading zeros added to it for length 16.
    i.e '0000000000123456' . If the length of dmb is less than 16 then leading zeros should be added to that value to make it 16 as length.
    Please tell me how to do it in ABAP Objects.

    Hi Camila
    Try to use the statement
    DATA: ALPHABET(15) VALUE '     ABCDEFGHIJ',
          M1(4)        VALUE 'ABCD',
          M2(6)        VALUE 'BJJCA '.
    SHIFT ALPHABET LEFT DELETING LEADING M1.
    The field
    ALPHABET
    remains unchanged.
    SHIFT ALPHABET LEFT DELETING LEADING SPACE.
    The field ALPHABET now has the following contents:
    'ABCDEFGHIJ     '.
    SHIFT ALPHABET RIGHT DELETING TRAILING M2.
    <b>ALPHABET</b> now has the following contents:
    '      ABCDEFGHI'.
    <u><b>IN CHARACTER MODE</b></u>
    <b>Effect</b>
    This is the default setting (see above), and the addition is therefore optional.
    <b>Note
    Performance:</b>
    For performance reasons, you should avoid using SHIFT in WHILE loops.
    The runtime required to shift a field with length 10 by one character to the right or left requires about 5 msn (standardized microseconds). A cyclical shift requires around 7 msn. The runtime for the ...
    LEFT DELETING LEADING
    ... variant is around 3.5 msn, for ...
    RIGHT DELETING TRAILING
    ... around 4.5 msn.
    Reward all helpfull answers
    Regards
    Pavan

  • How do I use the print function to output a numeric variable with a fixed amount of leading zeroes

    I need to create an output from a T-SQL query that picks a numeric variable and uses the print function to output with leading zeroes if it is less than three characters long when converted to string.  For example if the variable is 12 the output should
    be 012 and if the variable is 3 the output should be 003.
    Presently the syntax I am using is PRINT STR(@CLUSTER,3) .  But if @CLUSTER which is numeric is less than three characters I get spaces in front.
    Please help!

    >> I need to create an output from a T-SQL query .. <<
    NO! NO! In RDBMS, we have a presentation layer that handles displays. We do not ever do it in the database. This is fundamental. But more than that, the purpose of PRINT is for debugging in T-SQL and never for output.
    You are still writing 1960's COBOL or BASIC, but you want to to it in SQL.  You probably picked the wrong data type (a numeric that should be a string) and are trying to repair your design error.  
    --CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
    in Sets / Trees and Hierarchies in SQL

  • IR - Column with leading Zeros issue

    Hello,
    I've got an IR report which includes as "default report settings" 1 column with leading 0s. In order to export to Excel that column as text rather than as a numeric I followed a workaround proposed before in this forum (excel copy drops leading zeros
    In essence this workaround is to create an identifical column but in "excel text format" and display the columns depending on the request value: INSTR(NVL(:REQUEST,'YABBADABBADO'),'CSV') <> 0 for example.
    This works just fine for the default report.
    The problem arise when a user creates his own customise report that includes the mentioned column and saves it as a named report. Here, when the results are exported to excel the "excel" column does not appear.
    In fact, just hiding one of the displayed columns produces the same undesired result.
    I would appreciate any comments or suggestions.
    Many thanks
    Edited by: Javier Gil on Jul 20, 2010 7:52 AM

    I have found a better method. In your IR query:
    SELECT LPAD(v.vendor, 7, ' ') vendor,
    /*Just LPAD to a length of the column defined in the database table or to 7, whichever is greater. */
    FROM v, r
    WHERE v.VENDOR = r.VENDOR
    AND date_rcv <= to_date(:P150_CUTOFF,'yyyy/mm/dd')
    AND inv_nbr = ' '
    AND to_stores <> 'T'
    AND (V.VENDOR = RPAD(:P150_VENDOR,10,' ') OR :P150_VENDOR = 'ALL')
    When you download to Excel by Download/XLS (Request=XLS), it preserves the leading zeros.
    In the case of dates, you should LPAD 10 minimum in this format.
    LPAD(to_char(date_rcv,'MM/DD/YY'), 10, ' ') date_rcv,
    I haven’t tried it yet but I think in the case of ‘MM/DD/YYYY’, you should LPAD 12 minimum in this format.
    LPAD(to_char(date_rcv,'MM/DD/YYYY'), 12, ' ') date_rcv,
    Drawbacks of this method:
    Since the string has leading white spaces, you cannot use the filter for the ‘=’ comparison operator. Even filtering using leading white spaces will not return anything. You must use the LIKE and NOT LIKE operator instead.
    Advantages of this method over the original one I posted yesterday:
    1)     You do not have to create another column for download, just one column will suffice.
    2)     Even though the query has leading white spaces, they will not display in the IR region.
    Edited by: richardlee on Aug 5, 2010 11:10 AM
    Edited by: richardlee on Aug 5, 2010 11:16 AM

  • IR truncating leading zeros in my popup window report

    Hello,
    I am using IR_columnname, for one of the columns in my report which is a popup window report.
    My problem is that IR_column search filter in my popup window is truncating the leading zeros.
    I am getting the value but it is truncating the leading zeros.
    like say if the deptno is something like 020 or 0020 in the parent window.
    the IR_columnname value is taking '20' (its truncating leading zeros) with this filter its not dispalying the result in my popup window.
    can anyone help me out with this.
    thanks.

    How are you passing values to the IR filter? There could be a possibility that you source logic is truncating the leading zeros.
    Thanks,
    Manish

  • How do I add leading zero(s) to exported files' names?

    I'm using Lightroom 1.4 on an iMac, with OS X 10.4. When I export a batch of photos, they get numbered automatically. For example, if they're pictures of my dog, I'll specify "Dog" as the name to be used and 1 as the starting number. Lightroom will then export them as "Dog-1.tif" and "Dog-2.tif" and so on.
    The problem is that when I then load these files into another application, it thinks that "Dog -1.tif" should be followed by "Dog-11.tif," then "Dog-12.tif," and so on to "Dog-19.tif" and then "Dog-2.tif," "Dog-20.tif," "Dog-21.tif," etc.
    One solution to this would be to have them numbered as 01, 02, 03. . . 09, 10, 11, etc. Rather than add those leading zeros to the file names manually, I'd like to have Lightroom put them in when it exports the files, but I can't figure out how to do that. I've tried entering 01 as the starting number in the "Export" dialogue box, but that doesn't do the trick.
    Can anybody tell me how to get Lightroom to add a leading zero (or zeros, when I export more than 99 files at a time) to the file names?

    >What if I just wanted to name the images 0001, 0002, 0003, etc? Can't seem to figure that out.
    In the Filename Template Editor, simply insert the [Sequence # (0001)] token as the only entry in the template field.

  • Remove the leading Zero from the Query output in SAP BW ?

    Hi
    Experts,
    Vendor Number loaded  as   (0000010076) from R/3 to SAP BW.
    How to remove  Prefix  of Zero for  the Vendor Number(0000010076)  from Quey outpt.
    Regards.
    ASIT

    Hi,
    Please check out this thread.
    Remove leading zeros
    Also check if there is any conversion routine used for that particular infoobject.
    If ALPHA conversion is selected for your infoobject then it will automatically take away the leading zeros at query level.
    Regards,
    AL
    Edited by: AL1112 on Sep 16, 2011 9:15 AM

  • How can we put the leading zeros for the extract file.

    hello experts..
           Iam extracting values from one ztable in this for one filed length will be 2, for this field i need leading zero s at the time of extract... please help me....

    Hi,
    Declare the field as NUMC data type, automatically you will get the leading zeroes.
    Regards,
    Subramanian

  • How can I remove the leading zeros on jpg files?

    I'm looking for a way to remove the leading zeros on over 1000 jpg files, without changing the remaining digits in the file name. Is there some automated "batch" script?
    i.e going from 003405607.jpg  to  3405607.jpg

    You could write an AppleScript. but it will be easier to get and use a third-party file renaming utility. I use the freeware NameChanger which works quite well.
    https://www.macupdate.com/app/mac/21516/namechanger
    Regards.

  • How to delete leading zeros in sap script

    Hi
    In sapscript iam facing an issue with num4 field.
    Iam using this field to display Serial.No
    it is displaying '1' as 0001 i want to display here 1 with out leading zeros.
    If there any solution let me know

    Hi,
    Try below code
    data: w_vbeln type vbak-vbeln,
    w_char(10).
    w_vbeln = '000012345'.
    write w_vbeln to w_char no-zero.
    or
    The function Module 'CONVERSION_EXIT_ALPHA_OUTPUT' is used to remove the leading zeros in a field.
    the following is a sample code which i have used for 'Commitment item' in my report. replace the field with your required field.
    CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
    EXPORTING
    INPUT = IT_FMIT1-RFIPEX
    IMPORTING
    OUTPUT = IT_FMIT1-RFIPEX.
    Regards,
    Chandru

  • Visual Studio Projects Not Showing FileVesion Leading Zeroes in File Properties

    I created a simple Visual Studio 2013 windows form application setting the AssemblyInfo.cs file as show below.
    // You can specify all the values or you can default the Build and Revision Numbers
    // by using the '*' as shown below:
    // [assembly: AssemblyVersion("1.0.*")]
    [assembly: AssemblyVersion("1.0.0.0227")]
    [assembly: AssemblyFileVersion("1.0.0.0227")]
    [assembly: AssemblyInformationalVersion("0.0.0.0227")]
    I built the application and went to the Windows File Explorer and brought up the file properties. What I see is that the product version showing the leading zeros, but the file version field does not show the leading zeros.
    It appears to be a bug either with Visual Studio or with Windows. Which one is it and is there a fix?

    Hi Sarah,
    We can't see the screenshot. Do you mean you use Windows Explorer to browse to the AssemblyInfo.cs file and check the property?
    If you change the product version or the file version from the AssemblyInfo.cs file, you need to firstly rebuild the assembly, then if you go to the debug/release folder, check the property of the assembly file, the Details tab will show you the corresponding
    changes of these properties. It's the assembly property but not the cs file property.
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

Maybe you are looking for

  • WRT54G v6.0 Disconnects From Server After Ten Minutes

    I posted this once before and somehow it got....deleted? Anyway....here we go again. I purchased A WRT54G over the holidays. It has worked fine for me with the exception of a real estate data source (server) that I need to use for my business. I can

  • PDF form auto-notification/pop-up on 3rd Party PDF readers

    My livecycle generated PDF form wants to work only on Acrobat reader for user input and most importantly when summing numbers in the table field. I currently enable usage rights under Acrobat 9.  The problem is that when people attempt to open the fo

  • Why can't I log in to convert to excel?

    Why can't I log in to create an excel spreadsheet from a PDF document

  • Getting page number while JSP printing- link rel="alternate" media="print"

    <link rel="alternate" media="print" href="reportprint.jsp" This i am using for printing report.jsp. report.jsp contains more than 2000 records. I need to have the page number to put the column header in each page. What is the possible way to get the

  • Swing program accessing oracle

    this program does not give output when oracle is being accessed.... please help sks_bank is a table in oracle database having account number, name, balance import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.sql.*; public cl