Nr of elements in string[] list ?

Hi,
is there easy way to find out how many Strings (object) there are in a string[] buffer.
I have a method :
myMethod(string[] list)
// here i want to find out how many Strings are passed into this method
thanks
Indy

int numStrings = list.length;

Similar Messages

  • Java 1.5 - Each Element of a List Cannot Be An Array?

    I plan to create a List and each element of this List is a String Array.
    First, I declared a List:
         private static List<String> recursiveTextArray = new ArrayList<String>();And I want to build this List by adding one Array at a time:
    recursiveTextArray.add( title );where
    private String[] title;
    title = new Array(3);I got syntax error saying: "The method add(String) in the type List<String> is not applicable for the arguments (String[]).
    I cannot figure out what the compiler is complaining about. How do I fix the problem? Thanks in advance.

    I think that I have some idea about what is going on. Because Array is an object, I should:
    private static List<Object> recursiveTextArray = new ArrayList<Object>();But the Java statement shown right above has a syntax error: "Syntax error on token ";", , expected"
    I have no clue why there is such a syntax error.

  • Cannot convert an element for a list ton Integer

    I have my list [1, 2, 999] I'm trying to change the the last element of my list by -999, I m getting an error message
    int val = 999;
    String s1 = (String)list.get(list.size()-1);
    int s2 = Integer.parseInt(s1);
    if(s2 == val)
         // Replace the value 999 by -999
         list.add(list.size(), -999);

    ronisto wrote:
    52 System.out.println("La position du dernier est: "+list.size());
    53          
    54          String s1 = (String)list.get(list.size()-1);Looks like the error is really on line 54. The error seems to be that the element in the list is an Integer, not a String. The best was to avoid this is to use generics:
    List<Integer> numbers = new ArrayList<Integer>();http://java.sun.com/docs/books/tutorial/collections/index.html
    http://java.sun.com/docs/books/tutorial/extra/generics/index.html

  • Is it possible to rearrange the elements in a List after removing indexes?

    Hello,
    I am hoping someone can help me out w/a question.
    I have a list
    List<String>  Labels = new ArrayList<String> ();and I add 3 elements in the list
    labels.add("one"); //index 0
    labels.add("two"); //index 1
    labels.add("three");  //index 2Later on in the program I remove 2 indexes,
    labels.remove(0);
    labels.remove(2);When i try to iterate through labels it throws
    Exception in thread "AWT-EventQueue-0" java.lang.IndexOutOfBoundsException: Index: 1, Size: 1I perfectly understand the error. My question is this: after removing the indexes, how can i rearrange the list so that the one element that is left (currently at index 1) is set at index 0 so that it doesn't throw an exception ? is this doable ?
    Thanks very much for your help!!

    va97 wrote:
    Hello,
    I am hoping someone can help me out w/a question.
    I have a list
    List<String>  Labels = new ArrayList<String> ();and I add 3 elements in the list
    labels.add("one"); //index 0
    labels.add("two"); //index 1
    labels.add("three");  //index 2Later on in the program I remove 2 indexes,
    labels.remove(0);
    labels.remove(2);
    This doesn't work!
    Before those call the List looks like this:
    [one, two, three].
    After you call remove(0), it will look like this:
    [two, three]
    Now, when you try to call remove(2), it will throw an IndexOutOfBoundsException, as there is nothing at index 2 anymore.
    I perfectly understand the error. My question is this: after removing the indexes, how can i rearrange the list so that the one element that is left (currently at index 1) is set at index 0 so that it doesn't throw an exception ? is this doable ?I'm afraid you don't understand the error message correctly, since then your question would be different.
    The error message says "you tried to access something at index 1, but this list only is of size 1". This means that the only valid index at that moment is 0.

  • �Map String, List ?

    Hello!
    In my application I would like to use a data type to represent a pair "<city1>, <inferior limit>", "<city1>, <superior limit>", "<city2>, <inferior limit>", "<city2>, <superior limit>", "<city3>, <inferior limit>", "<city3>, <superior limit>", etc. So when I looked for the first element (city) I'd get two values (two limits).
    What would be the best option?
    I thought I could use for example:
    Map<String, List> map = new HashMap<String, List>();
    "String" will have the name and "List" will have two elements: inferior and superior limit.
    If this were reasonable option, how could I put elements in that map? And how could I get the limits?
    Thanks in advance :)

    You shouldn't use List for this purpose: you have exactly 2 elements of certain meaning (not collection of numerous elements), so you should better create a class to hold them and use Map<String,YourClass>.

  • XML Element to string conversion returning null

    Hi,
    When i try to convert XML Element to string using toString() API, it returns something like [device: null] where device is element tag.
    Code is as follows -
    Document xmlDoc;
    DOMParser parser = (DOMParser)Class.forName("org.apache.xerces.parsers.DOMParser").newInstance();
    parser.setFeature( "http://apache.org/xml/features/dom/defer-node-expansion", true );
    parser.parse(new InputSource(new StringReader(tableStr)));
    xmlDoc = parser.getDocument();
    Element root = xmlDoc.getDocumentElement();
    NodeList nodeList = root.getElementsByTagName("device");
    Element deviceNode = (Element)nodeList.item(nodeList.getLength()-1);
    System.out.println(deviceNode.toString()); //prints [device: null] ????
    System.out.println(deviceNode.getAttribute("ipAddress")); //prints correct ip address
    Any idea why i am getting [device: null] when trying to convert Element to String though attribute value is retrieved.
    Thanks,
    Deepak

    Hello ,
    I want to get the root node (<ZTOP60_XML_TAG_STRUCTURE>
    ) of the following xml file .
    <?xml version="1.0" encoding="utf-8"?>
    <ZTOP60_XML_TAG_STRUCTURE>
         <MSGTYPE>NAPOBACK</MSGTYPE>
         <SNDPRN>657393485</SNDPRN>
         <RECEIVER/>
         <RCVPRN>GSOHUBDM1</RCVPRN>
         <PONUM/>
         <VENDCODE>0020040266</VENDCODE>
         <VENDUNS>002601768</VENDUNS>
         <PARTNERFUNC_WE>WE</PARTNERFUNC_WE>
         <PARTNERNUM_WE>C240</PARTNERNUM_WE>
         <LINE_ITEMS>
              <item>
                   <ITEMNUM>00687</ITEMNUM>
                   <POQTY>999999999.000</POQTY>
                   <BOQTY>1.000</BOQTY>
                   <GRQTY>7.000</GRQTY>
                   <NETVAL>339.65</NETVAL>
                   <PLANT>C240</PLANT>
                   <MATNUM>FE-26865-01</MATNUM>
                   <MATDESC>PTR, T632, LEXMARK 5-BIN MAILBOX</MATDESC>
                   <PONUMBER>6500022388</PONUMBER>
                   <EKGRP>U17</EKGRP>
                   <DISPO>N07</DISPO>
              </item>
              <item>
                   <ITEMNUM>00178</ITEMNUM>
                   <POQTY>999999999.000</POQTY>
                   <BOQTY>1.000</BOQTY>
                   <GRQTY>303.000</GRQTY>
                   <NETVAL>18.62</NETVAL>
                   <PLANT>C240</PLANT>
                   <MATNUM>FE-ZZYRG-01</MATNUM>
                   <MATDESC>FDD,FDI-PC,1.44MB,3.5 ,HH</MATDESC>
                   <PONUMBER>6500022388</PONUMBER>
                   <EKGRP>U17</EKGRP>
                   <DISPO>N07</DISPO>
              </item>
              <item>
                   <ITEMNUM>00157</ITEMNUM>
                   <POQTY>999999998.000</POQTY>
                   <BOQTY>24.000</BOQTY>
                   <GRQTY>303.000</GRQTY>
                   <NETVAL>26.25</NETVAL>
                   <PLANT>C240</PLANT>
                   <MATNUM>FE-25094-01</MATNUM>
                   <MATDESC>MOUSE,PC,3BUT,,INTELLIMOUSE,PS2</MATDESC>
                   <PONUMBER>6500022388</PONUMBER>
                   <EKGRP>U17</EKGRP>
                   <DISPO>N07</DISPO>
              </item>
              <item>
                   <ITEMNUM>00881</ITEMNUM>
                   <POQTY>999999999.000</POQTY>
                   <BOQTY>1.000</BOQTY>
                   <GRQTY>62.000</GRQTY>
                   <NETVAL>368.80</NETVAL>
                   <PLANT>C240</PLANT>
                   <MATNUM>FD-66515-01</MATNUM>
                   <MATDESC>ITU MODULE ASM</MATDESC>
                   <PONUMBER>6500022388</PONUMBER>
                   <EKGRP>U17</EKGRP>
                   <DISPO>N07</DISPO>
              </item>
              <item>
                   <ITEMNUM>00223</ITEMNUM>
                   <POQTY>999999999.000</POQTY>
                   <BOQTY>1.000</BOQTY>
                   <GRQTY>377.000</GRQTY>
                   <NETVAL>459.28</NETVAL>
                   <PLANT>C240</PLANT>
                   <MATNUM>FD-65336-01</MATNUM>
                   <MATDESC>MAIN SYSTEM BOARD T23 (2647)</MATDESC>
                   <PONUMBER>6500022388</PONUMBER>
                   <EKGRP>U17</EKGRP>
                   <DISPO>N07</DISPO>
              </item>
              <item>
                   <ITEMNUM>00081</ITEMNUM>
                   <POQTY>999999999.000</POQTY>
                   <BOQTY>19.000</BOQTY>
                   <GRQTY>810.000</GRQTY>
                   <NETVAL>217.21</NETVAL>
                   <PLANT>C240</PLANT>
                   <MATNUM>FD-64199-01</MATNUM>
                   <MATDESC>QST- CADET 100</MATDESC>
                   <PONUMBER>6500022388</PONUMBER>
                   <EKGRP>U17</EKGRP>
                   <DISPO>N07</DISPO>
              </item>
              <item>
                   <ITEMNUM>00271</ITEMNUM>
                   <POQTY>999999999.000</POQTY>
                   <BOQTY>1.000</BOQTY>
                   <GRQTY>136.000</GRQTY>
                   <NETVAL>813.76</NETVAL>
                   <PLANT>C240</PLANT>
                   <MATNUM>FD-60065-01</MATNUM>
                   <MATDESC>SMART UPS 3000VA RM</MATDESC>
                   <PONUMBER>6500022388</PONUMBER>
                   <EKGRP>U17</EKGRP>
                   <DISPO>N07</DISPO>
              </item>
              <item>
                   <ITEMNUM>00791</ITEMNUM>
                   <POQTY>999999999.000</POQTY>
                   <BOQTY>1.000</BOQTY>
                   <GRQTY>3.000</GRQTY>
                   <NETVAL>201.73</NETVAL>
                   <PLANT>C240</PLANT>
                   <MATNUM>3X-PBXGG-AA</MATNUM>
                   <MATDESC>ATI 7500 PCI GRAPHICS</MATDESC>
                   <PONUMBER>6500022388</PONUMBER>
                   <EKGRP>U17</EKGRP>
                   <DISPO>N07</DISPO>
              </item>
              <item>
                   <ITEMNUM>00173</ITEMNUM>
                   <POQTY>999999999.000</POQTY>
                   <BOQTY>1.000</BOQTY>
                   <GRQTY>32.000</GRQTY>
                   <NETVAL>7.50</NETVAL>
                   <PLANT>C240</PLANT>
                   <MATNUM>12-56178-01</MATNUM>
                   <MATDESC>CARD GUIDE,SNAP-IN,LOW PROFILE,2.5 INCHE</MATDESC>
                   <PONUMBER>6500022388</PONUMBER>
                   <EKGRP>U17</EKGRP>
                   <DISPO>N07</DISPO>
              </item>
              <item>
                   <ITEMNUM>00309</ITEMNUM>
                   <POQTY>999999998.000</POQTY>
                   <BOQTY>15.000</BOQTY>
                   <GRQTY>71.000</GRQTY>
                   <NETVAL>51.23</NETVAL>
                   <PLANT>C240</PLANT>
                   <MATNUM>30-51476-01</MATNUM>
                   <MATDESC>VHDI-CABLE WIDE 12 FT. DT-AB001-TQ</MATDESC>
                   <PONUMBER>6500022388</PONUMBER>
                   <EKGRP>U17</EKGRP>
                   <DISPO>N07</DISPO>
              </item>
              <item>
                   <ITEMNUM>00194</ITEMNUM>
                   <POQTY>999999999.000</POQTY>
                   <BOQTY>1.000</BOQTY>
                   <GRQTY>147.000</GRQTY>
                   <NETVAL>345.48</NETVAL>
                   <PLANT>C240</PLANT>
                   <MATNUM>29-33689-01</MATNUM>
                   <MATDESC>PTR,IMP9,B/W,PAR/SER,110/240,R</MATDESC>
                   <PONUMBER>6500022388</PONUMBER>
                   <EKGRP>U17</EKGRP>
                   <DISPO>N07</DISPO>
              </item>
         </LINE_ITEMS>
    </ZTOP60_XML_TAG_STRUCTURE>
    I wrote the following lines of code ..
    FTI .. >> String strMsg =((javax.jms.TextMessage)msg).getText();
    StrMsg is a string that represents an xml file .
    DocumentBuilderFactory docfactory = DocumentBuilderFactory.newInstance();
                   DocumentBuilder builder = docfactory.newDocumentBuilder();
                   Document doc = builder.parse(new InputSource(new StringReader(strMsg)));
                   Element root = doc.getDocumentElement();
                   System.out.println("The root is " + root);
                   String strFileName = root+".xml" ;
                   System.out.println("The file name is " + strFileName);
                   File f = new File (strFileName);
                   FileOutputStream fos = new FileOutputStream( f );
                   for ( int j =0 ; j < strMsg.length(); j++)
                        char c = strMsg.charAt(j);
                        fos.write((int)c);
    I am getting the following error ...
    The root is [ZTOP60_XML_TAG_STRUCTURE: null]
    The file name is [ZTOP60_XML_TAG_STRUCTURE: null].xml
    Whey the file name or root is with special character [ ] and null ..
    I want just ZTOP60_XML_TAG_STRUCTURE.xml .
    Can anyone help me .
    thanks
    mahesh

  • Add an element to the list in run time

    There is an item in my form which is a list of values.It is getting populated based on a record group query.
    I want to let the user enter values at run time and add the values to the exiting list in the form and same
    should be added to the record group so that next time i open the form the added value can be seen.
    Is this possible?
    Regards,

    I have written this code on when_button_pressed trigger to populate the record group RGSTD and LOV(Name LOVSTD).
    I have added the element in the list using add_list_element built in. But it is not giving me proper results.
    Record group has two columns STDID and STDNAME.
    DECLARE
    ln_num NUMBER := 0;
    BEGIN
    ln_num := show_alert('ALERT15');
    IF ln_num = 88 THEN
    add_group_row('RGSTD', 1);
    set_group_char_cell('STDID', 1, 'ST00004');
    set_group_char_cell('STDNAME', 1, 'Add To List');   
    add_list_element('LOVSTD', 1, 'Add To List', 'Add To List');  
    ELSE
    NULL;
    END IF;
    END;Edited by: LostWorld on Feb 9, 2009 5:49 AM

  • Invalid element 'welcome-file-list' in content of 'web-app',

    HI, folks.
    I recently used struts to develop a simple web applicaiton, and whenever I tried to use tag libs
    such as /WEB-INF/struts-html.tld
    /WEB-INF/struts-html.tld and
    tried to compile it, it gives out compile error such as:
    Error(52,21): Invalid element 'welcome-file-list' in content of 'web-app', expected elements '[taglib, resource-env-ref, resource-ref, security-constraint, login-config, security-role, env-entry, ejb-ref, ejb-local-ref]'.
    if I remove the above tag libs, the jsp file compiles
    without any problem.
    Are you guys familiar with these problems?
    please let me know if I'm doing anything foolish.
    Thanks!

    Unless some other elements tag are not close correctly this error does not make sense. Can you cut and paste your web.xml?
    It should look something like:
    <?xml version = '1.0' encoding = 'windows-1252'?>
    <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
    <web-app>
    <welcome-file-list>
      <welcome-file>/untitled1.jsp</welcome-file>
    </welcome-file-list>
    <taglib>
      <taglib-uri>/WEB-INF/struts-html.tld</taglib-uri>
      <taglib-location>/WEB-INF/struts-html.tld</taglib-location>
    </taglib>
    </web-app>Charles.

  • Covert DOM element to String

    It sounds very simple, however could not find any solution using JAXP.
    What I need is that I have a DOM element, I want to convert the DOM element into String and store into the database. I used to do it using JDOM. It has a feature something like toString.
    I know that serialization is another option, however, want to know how to do this way.

    xmlString.getBytes()No, that causes your problem. Read the documentation to see what the getBytes() method does. Here's what you should do instead:Document document = documentBuilder.parse(new InputSource(new StringReader(xmlString)));This doesn't convert from String to bytes using a bad encoding. But you also say:
    xmlString contains Japanese characters and was originally from a xml file with UTF-8 encoing.In this case there's a good chance that in reading from the file to the String you have also failed to use UTF-8 to do the decoding. Why not just pass a File object to the parser and let it deal with the encoding issues? It knows what to do.

  • Dom element to string

    I have a method, the argument being passed in is a dom element.
    The method will convert the element(and child node) to string. The string is then passed into a buffer writer to write to a file.
    What is the easiest/fastest way to convert the dom element to string?
    Is there a better way to write the element to a file?
    Any sample code available?

    You could try something like this:
        String elementToString(Element element)
        throws Exception
            StringWriter sw = new StringWriter();
            TransformerFactory tFactory = TransformerFactory.newInstance();
            Transformer transformer = tFactory.newTransformer();
            transformer.setOutputProperty(OutputKeys.INDENT, "yes");
            transformer.setOutputProperty(OutputKeys.METHOD, "xml");
            transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
            DOMSource source = new DOMSource(element);
            StreamResult result = new StreamResult(sw);
            transformer.transform(source, result);
            return sw.toString();
        }Regards

  • I am not capable any more of deleting elements of my list of itunes wishes

    I am not capable any more of deleting elements of my list of itunes wishes
    What can i do???

    Hello, loulou6789. 
    You can still manage your iTunes Wish List.  The article below will walk you through the steps of deleting items you no longer want on your Wish List. 
    iTunes Store: How to use Wish List
    http://support.apple.com/kb/HT1368
    Cheers,
    Jason H. 

  • FRM-30351: No list elements defined for list item.

    Hello!
    i have a list_item with name NOMBRE and in a NEW_FORM_INSTANCE trigger i have the following pl/sql block to populate it:
    declare
         grp_producto recordgroup := find_group('RECORD_PRODUCTO');
         lst_item item := find_item('PRODUCTO.NOMBRE');
         status number;
    begin
         status := populate_group(grp_producto);
         clear_list(lst_item);
         populate_list(lst_item,grp_producto);
    end;
    when i run the form, this message appear
    FRM-30351: No list elements defined for list item.
    List NOMBRE
    and the list appear without elements
    ...can somebody explain me the solution or if i have to do another thing to populate the list?
    Thanks

    Hi Duncan!
    i rewrote the manually code and agregate the clear_list function that i think you refer with "Make sure that the block is empty before you do this". This work the first time but in the next time a change that i do in the database isn't reflected in the list, i think that my cursor mantain the old information, well, can you indicate me some way to clear the cursor or something similar? or explain me another solution?
    thanks so much!
    declare
    nombre_producto soportebwv2.producto.nombre%type;
    lst_item item;
    i number:=1;
    CURSOR cur IS
    select nombre
    from soportebwv2.producto;
    begin
    lst_item:= find_item('PRODUCTO.NOMBRE');
    clear_list(lst_item);
    open cur;
    loop
    fetch cur into nombre_producto;
    exit when cur%NOTFOUND;
    add_list_element(lst_item, i, nombre_producto, nombre_producto);
    i:=i+1;
    end loop;
    close cur;
    end;

  • No list elements defined for list item.

    hi master
    when i use list item and run then give this error
    FRM-30351: No list elements defined for list item.
    List PRODUCT_NO
    Created form file MODULE1.fmx

    Try posting your question to Forms

  • Element in two lists

    Hey,
    I got a class for a tabbing page that is stored in an ArrayList A. This list A
    contains various pages for a JTabbedPane. Only some of those pages will
    also be stored in another ArrayList B. Hence list B will be smaller than A.
    When I remove such a tabbing page in list A, I'll check also a certain
    boolean if it is contained in list B, too.
    How can I get the index now in list B in an elegant way? First I gave all of
    those tabbing page classes an index variable for B, that I could check. My
    problem was, it seems to be a bit clumsy and I need to update that variable
    after each action (add/remove). Now I thought about in case I'd like to
    remove a page, to run thru the list B and compare the elements in that list
    directly with the one which is to be removed or compare just hashCode's of
    these elements with the one to be removed, in case it would work?!
    Which solution solves my problem best? - the first using an additional variable, comparing the elements or comparing just the hashCodes with the one element to be removed? TIA

    don't know the 'best' way, but if the elements of B are added from A,
    this might be all you need to do.
        Object o = listA.get(2);//<--2 is any number
        for(int x = 0,y = listB.size(); x < y; x++)
          if(listB.get(x).equals(o))
            listB.remove(x);
        }

  • Compressing and decompressing a  string list

    Hi All,
    i need a help:
    i have an string list say,
    String sample="test";
    String sample1="test1";
    String sample2="test3";
    i want to compress this sample,sample1,sample2 and store that compressed results into another string variable.
    Ex:
    compressedSample=sample;
    compressedSample1=sample1;
    compressedSample2=sample2;
    similarly how can i uncompress the compressedSample,compressedSample1,compressedSample2 variables.
    Thanks in advance

    Try something like this :
    Compressing :
    ByteArrayOutputStream aos = new ByteArrayOutputStream();
    GZIPOutputStream gos = new GZIPOutputStream(aos);
    byte[] ba = "the_string_to_compress".getBytes();
    gos.write(ba,0,ba.length);
    gos.flush();
    String compressed_string = aos.toString();
    gos.close();
    Decompressing :
    GZIPInputStream zin = new GZIPInputStream( new ByteArrayInputStream( compressed_string.getBytes() ) );
    StringBuffer dat = new StringBuffer();
    byte[] buf = new Byte[128];
    for(int r; (r=zin.read(buf))!=-1;) dat.append( new String(buf,0,r) );
    zin.close();
    String org_string = dat.toString();

Maybe you are looking for

  • Weird behavior in master-detail

    Dear Forum, I need to implement an application but I still have a halting error. I have this strange problem and I'll try to explain. I have this masterscreen with search functionality. When I do a search, I get a result. When I now enter the details

  • G5 suddenly will not boot up.

    Ok...this is serious for me, so I'm panicking. First of all, I have a 2.0ghz Dual G5 with two 23"monitors, within the G5 is 2 DSP protools cards, a LaCie external dvd-rw drive, and a 260G external LaCie harddrive. This is pretty much the load. Anyway

  • Web Services in an EAR Deployment

    On deploying an EAR that includes a EJB web service JAR, I find that the WSDL url generated on the Web Services page is incorrect. For example for a web service named WebService1, the WSDL link shown on the WebServices page is ...oraclecloudapps.com/

  • 2 optical drives on a powermac G4?

    I see 2 optical drive 'doors' on the front of my G4. I use only one (CD - DVD) What is the other one for?

  • Need help in HR - CATS enhancements

    Hello everyone, I have a requirement where in i have to use a field that is not availaable in cats0003 enhancement's fuction exit import/table fields.The field is catsd-day# 's.I have to validate on these catsd-day01....fileds which are not available