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.

Similar Messages

  • Which interface would you use to list each element of a vector?

    Which interface would you use to list each element of a vector?

    The laugh's on you, twit! Nobody takes kindly to lazy bums trying to cheat on their homework nor exams. Take a hike loser!

  • Sorting a vector where each element is a vector

    Hi,
    Sorry for the post but I can't seem to get my head around sorting in Java using Comparator.
    I've a vector where each element is a vector containing strings, integers and doubles and the first element of each vector is a double.
    I need to sort the vector based on this first value of each element which is a vector.
    Hope some can help,
    Thanks in advance,
    Lou

    Here is a generic comparator you can use to sort a List. Vector implements the List interface to you can sort the Vector.
    import java.util.Comparator;
    import java.util.List;
    * A comparator to sort Lists of data based on a column within each List
    public class ListComparator implements Comparator
        private int column;
        private boolean ascending;
        ListComparator(int column, boolean ascending)
            this.column = column;
            this.ascending = ascending;
        public int compare(Object a, Object b)
            List v1 = (List)a;
            List v2 = (List)b;
            Object o1 = v1.get(column);
            Object o2 = v2.get(column);
            // Treat empty strings like nulls
            if (o1 instanceof String && ((String)o1).length() == 0)
                o1 = null;
            if (o2 instanceof String && ((String)o2).length() == 0)
                o2 = null;
            // Sort nulls so they appear last, regardless  of sort order
            if (o1 == null && o2 == null) return 0;
            if (o1 == null) return 1;
            if (o2 == null) return -1;
            //  Compare objects
            if (o1 instanceof Comparable)
                if (ascending)
                    return ((Comparable)o1).compareTo(o2);
                else
                    return ((Comparable)o2).compareTo(o1);
            else  // Compare as a String
                if (ascending)
                    return o1.toString().compareTo(o2.toString());
                else
                     return o2.toString().compareTo(o1.toString());
    }You invoke the sort by using:
    Collections.sort(yourVector, new ListComparator(column, ascending));

  • 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.

  • 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

  • Plz help! how to create a LinkedList inside each element of ArrayList

    how do i create a LinkedList inside each element of ArrayList

    how do i create a LinkedList inside each element of
    ArrayListYou really should read the API documentation and if you would you would see that you can construct a new ArrayList like this:
    ArrayList list = new ArrayList();and you can add to it like this
    list.add(new LinkedList());and now your list contains a new LinkedList at position 0 wich of course would be a LinkedList with some purpose not just a new empty one like in the example above. You could do something like this:
    ArrayList list = new ArrayList();
    LinkedList linkedList1=new LinkedList();
    // add something to linkedList1
    list.add(linked);
    LinkedList linkedList2=new LinkedList();
    // add something to linkedList2
    list.add(linked);
    LinkedList linkedList3=new LinkedList();
    // add something to linkedList3
    list.add(linked);and so one..
    bopen, hope this helps

  • 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);
        }

  • 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.

  • How to create a background image for each item in a List object

    Hello.
    I am trying to create a background image that displays whenever a user posts something to a list.  For example when a user posts text it would appear in a list.  The new item in the list would contain a specific background image with the users text appearing on top of the background image.  I do not want a background image for the entire list, rather each item within the list.
    I am not sure how clear this is so I added an image below.  When a user enters text in and clicks the "post-it" button their text would appear below with the sticky note background. 
    I am not sure which list type would be best for this problem or how to create insert the image, so I am open to suggestions. 
    Thank you for your help.  Any advice or guidance will be greatly appreciated!

    Hi
    the easiest way would be with itemRenderer.
    You have to do two things:
    1. In your list declaration use a item renderer: <mx:List itemRenderer="myRenderer"/>
    2. create a flex component myRenderer that will be the single item. This can be a canvas with a background image and a text field on it.
    When you add a new item to the list, a new myRenderer item will be created and the data property will be passed to it. So you have to put "data" in your textField.
    If you need more help try looking at Tour de Flex samples, they're pretty easy.
    Andrei

  • How to prevent JaxB creation of 2 Interfaces for each Element?

    hi,
    does any body know how to prevent JaxB creation of 2 Interfaces for each Element (The Content Interface and the element interface)?
    I want to configure JaxB to use only one Interface and only one implementation Class.
    Thank's,

    I am sorry I can not answer your question, I have got the same problem. Could you please email me to
    [email protected] when you know the answer, please.
    I have a question for you. When and complex type is validated, I get the object which contains the error. ( or objects ).
    However. How do know the position in the actual parent object. basically. Is there a way to know exactly the position of that attribute in that object. I need to store errors strings.
    The first problem derives from this one:
    It is not possible to execute validate function for a primitive attribute inside an structure.
    I would appreciate your help.
    Thanks.
    Gustavo.

  • I want to create an array that goes into a case structure where each element in the array is an individual case and gets done in order

    I want to create an array that goes into a case structure where each element in the array is an individual case and gets done in order. Any ideas, I've been playing with the idea but have had no luck, is this even possible?

    Hi,
    Please check it out the attached Vi.. Is this you need?
    Sasi.
    Certified LabVIEW Associate Developer
    If you can DREAM it, You can DO it - Walt Disney
    Attachments:
    Event.vi ‏11 KB

  • Java.lang.ClassCastException: oracle.xml.parser.v2.XMLText cannot be cast to org.w3c.dom.Element

    Hello
    I am getting java.lang.ClassCastException: oracle.xml.parser.v2.XMLText cannot be cast to org.w3c.dom.Element error. This code is in java which is present in java embedding.
    The SOA is parsing the xml in java code using oracle.xml.parser.v2 . This wont be a problem if the SOA uses default w3c DOM parser. How do i force SOA to use w3c DOM parser.
    Is there any thing i can do with class loading?
    Kindly help.
    Regards
    Sharat

    Can you paste your java code here ? I assume, you must have tried type-casting.

  • How to write each element of a set to the excel sheet?

    I am trying to iterate through each element of the set and write each of them to an excel file? Can Somebody help me to achieve this?
    Code snippet is:
    Iterator<String> nameIterator = names.iterator();
        for(int size = 0;size<names.size();size++){       
      row = mdm_lastLoginDate.createRow(size);
      //cell = row.createCell(1);
      while(nameIterator.hasNext()){
      String setName = nameIterator.next();
      cell = row.createCell(1);
      cell.setCellValue(setName);
      System.out.println("setName:->"+setName);
      mdm_lastLoginDate.autoSizeColumn(size);
    above code prints each element in the console but not getting each value in the excel file. I am only getting the last value.
    Thanks & regards
    Amita

    As already communicated several times to you - please use the correct space for your posts.
    I'll move this thread again to Master Data Management (SAP MDM), however - and for the last time - please get familiar with The SCN Rules of Engagement and note that your account will be disabled if you repeatedly fail to follow them.
    --Vlado (SCN Moderator)

  • 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

  • How to average each element in an array

    I have data from a Gage Card that I would like to average.  I am tuning a laser over a 50 mA range and for each 1mA increment in current, I am taking 100 scans.  Each scan consisting of about 200 points.  I cannot average more than 10 shots using the Gagecard so I would like to capture 100 scans, and average them to reduce noise.  Currently, I have my capture vi inside of a for loop which repeats 100 times and each scan writes to a file, but I would like ony 1 scan (the lower noise averaged one) per current increment.  
    How can I average each element of 100 arrays and output this to an array?
    Thanks for the help 

    It sounds like you want to average element 0 across 100 arrays and make that element 0 of the new averaged array.  Then average element 1 across 100 arrays and make that element 1 of the new array ...   ?????
    How are you working with your 100 1-D arrays now? 
    What you should do is make a 2-D array where one dimension is 100 (for the number of individual arrays) and the other dimension is how many elements are in those 100 1-D arrays.  Then you can use for loops with auto indexing to break the 2-D array down into each row or column, do the average of that array, and autoindex on the other side to build back up into the new 1-D array of averages.  You may need to to a transpose array going into your for loop in case the arrays are indexed in the wrong direction.
    Message Edited by Ravens Fan on 01-21-2008 04:26 PM
    Attachments:
    Example_BD.png ‏6 KB

Maybe you are looking for