Problem at iteration (ArrayList)

I`e made a soft wich writes elements from an array list to a table.
     int c=0;
     for (int a=0;a<(tabela.getRowCount());a++)
          for (int b=0;b<(tabela.getColumnCount());b++){
               tabela.setValueAt(list.get(c),a,b);
where tabela is the Table and list is the ArrayList. This version put into each row the element from the first position of the array list (because c=0). When i run this version, there are no problems. But if I increment c at each step (to put the nex value from the arraylist to the next row) i get this error message:
Exception in thread "AWT-EventQueue-0" java.lang.IndexOutOfBoundsException: Index: 4, Size: 4
     at java.util.ArrayList.RangeCheck(Unknown Source)
     at java.util.ArrayList.get(Unknown Source)
     at BazaDeDate.creazaTabela(BazaDeDate.java:100)
     at BazaDeDate.<init>(BazaDeDate.java:64)
     at Fereastra$6.actionPerformed(Fereastra.java:151)
     at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
     at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
     at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
     at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
     at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
     at java.awt.Component.processMouseEvent(Unknown Source)
     at javax.swing.JComponent.processMouseEvent(Unknown Source)
     at java.awt.Component.processEvent(Unknown Source)
     at java.awt.Container.processEvent(Unknown Source)
     at java.awt.Component.dispatchEventImpl(Unknown Source)
     at java.awt.Container.dispatchEventImpl(Unknown Source)
     at java.awt.Component.dispatchEvent(Unknown Source)
     at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
     at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
     at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
     at java.awt.Container.dispatchEventImpl(Unknown Source)
     at java.awt.Window.dispatchEventImpl(Unknown Source)
     at java.awt.Component.dispatchEvent(Unknown Source)
     at java.awt.EventQueue.dispatchEvent(Unknown Source)
     at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
     at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
     at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
     at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
     at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
     at java.awt.EventDispatchThread.run(Unknown Source)
This is how i increment c.
     int c=0;
     for (int a=0;a<(tabela.getRowCount());a++)
          for (int b=0;b<(tabela.getColumnCount());b++){
               tabela.setValueAt(list.get(c),a,b);
Thanks for any good suggestions.

Really? you don't understand what "Array Index Out Of Bounds" means?
You've tried to access something outside of your list. Don't do that.
Figure out why your list contains fewer items than your table has slots for; or stop assuming there are enough.

Similar Messages

  • Problem when iterating with JSTL

    hi ,
    i have occured a problem when iterating with JSTL
    althought this error,my application works fine but i would like to know why this error:
    ther is my iteration code:
    <c:forEach items="#{sWIMmoduleStatistiques.listeModules}" var="m">
               <h:panelGroup>
                <br>
                 <div class="connectorChartHeader" onclick="toggleImage('${m.nomChart}');" >
                <span class="headerTitle">${m.nom}</span>
            </div>
                   <br><br>
                   <img src="${m.nomChart}" id="${m.nomChart}" />
               </h:panelGroup> 
           </c:forEach>       
         the error is:
    javax.servlet.jsp.JspTagException: Don't know how to iterate over supplied "items" in <forEach>
         at org.apache.taglibs.standard.tag.common.core.ForEachSupport.toForEachIterator(ForEachSupport.java:274)
         at org.apache.taglibs.standard.tag.common.core.ForEachSupport.supportedTypeForEachIterator(ForEachSupport.java:238)
         at org.apache.taglibs.standard.tag.common.core.ForEachSupport.prepare(ForEachSupport.java:155)
         at javax.servlet.jsp.jstl.core.LoopTagSupport.doStartTag(LoopTagSupport.java:256)
         at org.apache.jsp.pages.modulesStatistiques_jsp._jspx_meth_c_005fforEach_005f0(modulesStatistiques_jsp.java:434)
         at org.apache.jsp.pages.modulesStatistiques_jsp._jspx_meth_h_005fpanelGrid_005f0(modulesStatistiques_jsp.java:399)
         at org.apache.jsp.pages.modulesStatistiques_jsp._jspx_meth_f_005fview_005f0(modulesStatistiques_jsp.java:181)
         at org.apache.jsp.pages.modulesStatistiques_jsp._jspService(modulesStatistiques_jsp.java:109)
         at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
         at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
         at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
         at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
         at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
         at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
         at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:630)
         at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:436)
         at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:374)
         at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:302)
         at com.sun.faces.context.ExternalContextImpl.dispatch(ExternalContextImpl.java:410)
         at com.sun.faces.application.ViewHandlerImpl.executePageToBuildView(ViewHandlerImpl.java:473)
         at com.sun.faces.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:141)
         at org.ajax4jsf.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:108)
         at org.ajax4jsf.application.AjaxViewHandler.renderView(AjaxViewHandler.java:196)
         at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:109)
         at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)
         at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
         at javax.faces.webapp.FacesServlet.service(FacesServlet.java:266)
         at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
         at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
         at TimeoutFilter.doFilter(TimeoutFilter.java:60)
         at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
         at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
         at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:177)
         at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:267)
         at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:380)
         at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:507)
         at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
         at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
         at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
         at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
         at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
         at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
         at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
         at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
         at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
         at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
         at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
         at java.lang.Thread.run(Thread.java:595)

    that line generated an error:
    java.lang.NumberFormatException: For input string: "class"
         java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
         java.lang.Integer.parseInt(Integer.java:447)
         java.lang.Integer.parseInt(Integer.java:497)
         javax.el.ListELResolver.coerce(ListELResolver.java:166)
         javax.el.ListELResolver.getValue(ListELResolver.java:51)
         javax.el.CompositeELResolver.getValue(CompositeELResolver.java:53)
         com.sun.faces.el.FacesCompositeELResolver.getValue(FacesCompositeELResolver.java:72)
         org.apache.el.parser.AstValue.getValue(AstValue.java:118)
         org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:186)
         org.apache.jasper.el.JspValueExpression.getValue(JspValueExpression.java:101)
         javax.faces.component.UIOutput.getValue(UIOutput.java:184)
         com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getValue(HtmlBasicInputRenderer.java:201)
         com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.getCurrentValue(HtmlBasicRenderer.java:284)
         com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeEnd(HtmlBasicRenderer.java:154)
         javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:861)
         javax.faces.component.UIComponent.encodeAll(UIComponent.java:946)
         javax.faces.render.Renderer.encodeChildren(Renderer.java:148)
         javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:837)
         javax.faces.component.UIComponent.encodeAll(UIComponent.java:936)
         javax.faces.component.UIComponent.encodeAll(UIComponent.java:942)
         com.sun.faces.application.ViewHandlerImpl.doRenderView(ViewHandlerImpl.java:271)
         com.sun.faces.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:202)
         org.ajax4jsf.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:108)
         org.ajax4jsf.application.AjaxViewHandler.renderView(AjaxViewHandler.java:196)
         com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:109)
         com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)
         com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
         javax.faces.webapp.FacesServlet.service(FacesServlet.java:266)
         TimeoutFilter.doFilter(TimeoutFilter.java:64)
         org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:177)
         org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:267)
         org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:380)
         org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:507)

  • Problems with Iterator

    Hello.
    I have some problems with Iterator when I try to loop through a Collection.
    for (Iterator i=arrFinallArray.iterator();i.hasNext();)           
                   objtable.insertRow(objtable.getRowCount(), new Object[] { arrFinallArray.iterator().next().getID(),
                        arrFinallArray.iterator().next().getFirstNumber(),
                        arrFinallArray.iterator().next().getSecondNumber(),
                        arrFinallArray.iterator().next().getThirdNumber(),
                        arrFinallArray.iterator().next().getMA(), arrFinallArray.iterator().next().getMG() });
                   i.next();
              }The results are stored in a Jtable object. The strange fact is that this code returned just first object from Collection.He is returned for each time when I iterate through Collection
    What's going on ?
    Many Thanks
    Julian A

    Calling iterator() gives you a new iterator. Calling next() on that will give you the first item.
    So if you call iterator().next() multiple times you will get the first item multiple times.
    You need to call next() on the reference to the original iterator, not create lots of new iterators.
    Better yet, when you want to iterate over all the contents of a collection use "enhanced for":
    for( final Object obj : collection ) {
    }

  • Problem with iterator in tableview

    Hi, Im having a problem with an iterator in a tableview. Sometime ago I use an iterator in a BSP with flow logic, I created the class fill the methods GET_COLUMN_DEFINITIONS and RENDER_CELL_START. And worked fine.
    Now, Im working in another BSP and this time I wanted to use MVC, so I have been reading but cant figure it out what Im missing out.
    In the controller of my page I add the Interface IF_HTMLB_TABLEVIEW_ITERATOR
    I ridefine the methods GET_COLUMN_DEFINITIONS and RENDER_CELL_START (I think that you dont have to redifine GET_COLUMN_DEFINITIONS but did it anyway just in case).
    This is my RENDER_CELL_START
      IF NOT ( p_column_key = 'ICON' ).
        RETURN.
      ENDIF.
      FIELD-SYMBOLS: <row> TYPE ANY, <col> TYPE ANY.
      DATA: ti_results TYPE ZBSPREP_VEND_T,
                 wa_results TYPE ZBSPREP_VEND.
      ASSIGN p_row_data_ref->* TO <row>.
      ASSIGN COMPONENT p_column_key OF STRUCTURE <row> TO <col>.
      wa_results = <col>.
      DATA: html_bee TYPE REF TO CL_BSP_BEE_HTML.
      CREATE OBJECT html_bee.
      LOOP AT it_results INTO wa_results.
        icon = CL_BSP_MIMES=>SAP_ICON( id = 'ICON_GREEN_LIGHT' ).
      ENDLOOP.
      p_replacement_bee = CL_HTMLB_IMAGE=>FACTORY( id = p_cell_id src = icon ).
    In my table view the column ICON doesnt show anything and the rare part is if I put breakpoint in the method and execute the page doesnt stop.
    So I dont know if Im missing something.
    My tableview layout is this:
    <htmlb:tableView id             = "Monitor"
                                     selectionMode  = "SINGLESELECT"
                                     onRowSelection = "rowSelection"
                                     table          = "<%= it_results %>"
                                     iterator        = "<%= iterator  %>"
                                     design         = "ALTERNATING"
                                     filter         = "SERVER"
                                     sort           = "SERVER"
                                     headerVisible  = "FALSE"
                                     footerVisible  = "FALSE">
    I declare a attribute iterator TYPE IF_HTMLB_TABLEVIEW_ITERATOR.
    Someone could give a hand ?

    Solved, I forget to set the attribute of the view in the REQUEST Method.
    result_view->set_attribute( name = 'iterator' value = me ).

  • Problem in calling arraylist from client

    Hi
    I am trying to execute a webservice program and facing some problems in the
    client side ,am trying to pass arraylist from client in weblogic8.1
    this is my client code and the error i am getting on the serverside all the files
    are getting generated properly,am i missing something.
    i have webserviceclient.jar in the classpath also,
    package examples.webservices.basic.statelessSession;
    import weblogic.utils.Debug;
    import java.util.ArrayList;
    import java.util.Collection;
    import javax.xml.soap.SOAPConstants;
    import javax.xml.namespace.QName;
    import javax.xml.rpc.Service;
    import javax.xml.rpc.encoding.TypeMapping;
    import javax.xml.rpc.encoding.TypeMappingRegistry;
    import weblogic.xml.schema.binding.internal.builtin.JavaUtilArrayListCodec;
    import weblogic.xml.schema.binding.internal.builtin.JavaUtilCollectionCodec;
    public final class Client {
    private final static boolean debug = true;
    private final static boolean verbose = true;
    public Client() {}
    public static void main(String[] argv)
    throws Exception
    HelloWorldEJB_Impl ws = new HelloWorldEJB_Impl(argv[0]);
    HelloWorldEJBPort port = ws.getHelloWorldEJBPort();
    TypeMappingRegistry registry = ((Service)port).getTypeMappingRegistry();
    TypeMapping mapping = registry.getTypeMapping(SOAPConstants.URI_NS_SOAP_ENCODING
    mapping.register(
    ArrayList.class,
    new QName("java:language_builtins.util", "ArrayList"),
    new JavaUtilArrayListCodec(),
    new JavaUtilArrayListCodec()
    mapping.register(
    Collection.class,
    new QName("java:language_builtins.util", "Collection"),
    new JavaUtilCollectionCodec(),
    new JavaUtilCollectionCodec()
    ArrayList arrList = new ArrayList(1);
    arrList.add("ccc");
    arrList.add("bbb");
    port.sayHelloList(arrList);
    The error i am getting while compiling with ant is
    [javac] C:\bea\weblogic81\samples\server\examples\src\examples\webservices\b
    asic\statelessSession\Client.java:92: sayHelloList(java.lang.Object[]) in exampl
    es.webservices.basic.statelessSession.HelloWorldEJBPort cannot be applied to (ja
    va.util.ArrayList)
    [javac] port.sayHelloList(arrList);
    [javac] ^
    [javac] 1 error
    Kindly reply at the soonest
    Sindhu

    Hi
    I tried object[] that was working fine but the requirement for the project
    is that we should use arraylists.i found a solution like i overwrote the xml in
    client.jar but again looks like i have to regenrate the stubs.
    Is there any way to regenerate except using the clientgen
    this time i got
    run:
    [java] java.rmi.RemoteException: null; nested exception is:
    [java] java.lang.ClassCastException
    [java] at examples.webservices.basic.statelessSession.HelloWorldEJBPort
    Stub.sayHelloList(HelloWorldEJBPortStub.java:32)
    [java] at examples.webservices.basic.statelessSession.Client.main(Clien
    t.java:75)
    [java] Caused by: java.lang.ClassCastException
    [java] at weblogic.xml.schema.binding.internal.builtin.JavaUtilCollecti
    onCodec.serializeOneDimArray(JavaUtilCollectionCodec.java:90)
    [java] at weblogic.xml.schema.binding.SoapArrayCodecBase.gatherContents
    (SoapArrayCodecBase.java:442)
    [java] at weblogic.xml.schema.binding.CodecBase.serializeFill(CodecBase
    .java:279)
    [java] at weblogic.xml.schema.binding.CodecBase.serialize_internal(Code
    cBase.java:216)
    [java] at weblogic.xml.schema.binding.CodecBase.serialize(CodecBase.jav
    a:178)
    [java] at weblogic.xml.schema.binding.RuntimeUtils.invoke_serializer(Ru
    ntimeUtils.java:188)
    [java] at weblogic.xml.schema.binding.RuntimeUtils.invoke_serializer(Ru
    ntimeUtils.java:174)
    [java] at weblogic.webservice.core.DefaultPart.invokeSerializer(Default
    Part.java:324)
    [java] at weblogic.webservice.core.DefaultPart.toXML(DefaultPart.java:2
    97)
    [java] at weblogic.webservice.core.DefaultMessage.toXML(DefaultMessage.
    java:619)
    [java] at weblogic.webservice.core.ClientDispatcher.send(ClientDispatch
    er.java:206)
    [java] at weblogic.webservice.core.ClientDispatcher.dispatch(ClientDisp
    atcher.java:143)
    [java] at weblogic.webservice.core.DefaultOperation.invoke(DefaultOpera
    tion.java:444)
    [java] at weblogic.webservice.core.DefaultOperation.invoke(DefaultOpera
    tion.java:430)
    [java] at weblogic.webservice.core.rpc.StubImpl._invoke(StubImpl.java:2
    70)
    [java] at examples.webservices.basic.statelessSession.HelloWorldEJBPort
    Stub.sayHelloList(HelloWorldEJBPortStub.java:26)
    and my xml i changed this way
    <wsdd:type-mapping xmlns:wsdd="http://www.bea.com/servers/wls70"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
    <wsdd:type-mapping-entry xmlns:p1="java:language_builtins.util"
    type="p1:ArrayList"
    class-name="java.util.ArrayList"
    serializer="weblogic.xml.schema.binding.internal.builtin.JavaUtilArrayListCodec"
    deserializer="weblogic.xml.schema.binding.internal.builtin.JavaUtilArrayListCodec">
    </wsdd:type-mapping-entry>
    </wsdd:type-mapping>
    Sindhu
    "jas" <[email protected]> wrote:
    >
    If you haven't already ... please see the thread below .. This might
    be of sokme
    use
    http://newsgroups.bea.com/cgi-bin/dnewsweb?cmd=article&group=weblogic.developer.interest.webservices&item=4378&utag=
    cheers
    jas
    "sindhu" <[email protected]> wrote:
    Hi
    I am trying to execute a webservice program and facing some problems
    in the
    client side ,am trying to pass arraylist from client in weblogic8.1
    this is my client code and the error i am getting on the serversideall
    the files
    are getting generated properly,am i missing something.
    i have webserviceclient.jar in the classpath also,
    package examples.webservices.basic.statelessSession;
    import weblogic.utils.Debug;
    import java.util.ArrayList;
    import java.util.Collection;
    import javax.xml.soap.SOAPConstants;
    import javax.xml.namespace.QName;
    import javax.xml.rpc.Service;
    import javax.xml.rpc.encoding.TypeMapping;
    import javax.xml.rpc.encoding.TypeMappingRegistry;
    import weblogic.xml.schema.binding.internal.builtin.JavaUtilArrayListCodec;
    import weblogic.xml.schema.binding.internal.builtin.JavaUtilCollectionCodec;
    public final class Client {
    private final static boolean debug = true;
    private final static boolean verbose = true;
    public Client() {}
    public static void main(String[] argv)
    throws Exception
    HelloWorldEJB_Impl ws = new HelloWorldEJB_Impl(argv[0]);
    HelloWorldEJBPort port = ws.getHelloWorldEJBPort();
    TypeMappingRegistry registry = ((Service)port).getTypeMappingRegistry();
    TypeMapping mapping = registry.getTypeMapping(SOAPConstants.URI_NS_SOAP_ENCODING
    mapping.register(
    ArrayList.class,
    new QName("java:language_builtins.util", "ArrayList"),
    new JavaUtilArrayListCodec(),
    new JavaUtilArrayListCodec()
    mapping.register(
    Collection.class,
    new QName("java:language_builtins.util", "Collection"),
    new JavaUtilCollectionCodec(),
    new JavaUtilCollectionCodec()
    ArrayList arrList = new ArrayList(1);
    arrList.add("ccc");
    arrList.add("bbb");
    port.sayHelloList(arrList);
    The error i am getting while compiling with ant is
    [javac] C:\bea\weblogic81\samples\server\examples\src\examples\webservices\b
    asic\statelessSession\Client.java:92: sayHelloList(java.lang.Object[])
    in exampl
    es.webservices.basic.statelessSession.HelloWorldEJBPort cannot be applied
    to (ja
    va.util.ArrayList)
    [javac] port.sayHelloList(arrList);
    [javac] ^
    [javac] 1 error
    Kindly reply at the soonest
    Sindhu

  • Problem in iterating through huge number of entries ... memory issue

    I am having large number of entries in lacs.
    I need to check each entry with previous ones , so I need to iterate through the each and every entry previous to current entry.
    Here I have put all the entries in arraylist and I am iterating though this arraylist and validating current entry.
    As I am using the arraylist for storing all the entries , the system is taking lot of memory because I am putting all in the memory.
    Is there anyway to resolve this memory issue?

    If you have a hundred thousand entries, to verify all the entries you would need to compare the later entries with the earlier ones such that:
    Entry 1 = 100,000 accesses
    Entry 2 = 99,999 accesses
    Entry 5 = 99,995 accesses
    Entry 10 = 99,990 accesses
    Entry 99,990 = 10 accesses
    Entry 99,995 = 5 accesses
    Entry 99,999 = 1 access (only to be compared with the 100,000th entry)
    It would then make sense to keep a certain (fixed) amount of entries in memory, those which get accessed the most, then write to file those which get accessed the least frequently. Have a method that can decide, based on the index of the entry, whether to get it from the ArrayList or to read it from the file. That will give you good performance.
    BufferedReader would be a good candidate to read the file, because it can skip more bytes at once should you need a line very late in the file. Also consider using RandomAccessFile and seek(entryNumber * ENTRY_SIZE) if your data can be represented with a fixed size in bytes.
    s
    Edited by Looce at 2009-03-25 20:33:11 GMT [Added BufferedReader advice]

  • Problem comparing two ArrayLists, elements must match, order not important.

    Hello,
    I am new to Java and my assignment is:
    Write a method for the Purse class - public boolean sameCoins(Purse other), that checks whether the other purse has the same coins, perhaps in a different order.
    For example, the purses:
    *Purse[Quarter,Dime,Nickel,Dime]*
    and
    *Purse [Nickel,Dime,Dime,Quarter]*
    should be considered equal.
    You will probably need one or more helper methods.
    I was able to make a method to check if the purses match(sameContents), but I have not been able to check if they match just based on elements(sameCoins). We are not using Collections.
    Below is my Purse Class:
    import java.util.ArrayList;
    public class Purse {
        private ArrayList<String> coins;
        public Purse() {
            coins = new ArrayList<String>();
        public void addCoin(String coinName) {
            coins.add(coinName);
        public String toString() {
            String text = "Purse[ ";
            for (String a : coins)
                text += a;
            text += "]";
            return text;
        public boolean sameContents(Purse other) {
            boolean content = false;
            if (other.coins.equals(coins))
                content = true;
            return content;
        public boolean sameCoins(Purse other){
            boolean samecoins = true;
            for(String a: coins)
                for(String b: other.coins)
                    if (a.contains(b))
                        samecoins = true;
                    else
                        samecoins=false;
            return samecoins;
    }Any help would be appreciated.

    tipalm wrote:
    Well then my prof cant hold it against me can he!He sure can, if he wants to. I'll bet you 30 duke stars that if you hand in the program as-is and try to argue for using the Collections framework, he's going to say "I meant you couldn't use any of the static methods in the Collections framework, the whole point of the assignment was to work through the logic of iterating through the Lists" But hey, it's not my assignment, so good luck!
    Edit- I'm not saying that using the Collections framework (and its myriad static methods) is bad in any way. It's actually what you should use, assuming there are no academic "but don't use this shortcut" rules being applied. I just doubt that's your case here. I'd recommend looking into how the Collections framework works, and then implement your own algorithm based on that.
    Edited by: kevinaworkman on Oct 29, 2009 10:13 AM

  • [JS CS3] Problem with iterating xml tags

    Hello,
    Below is a script that is supposed to find text in a document and then tag it with an xml tag. I have run into a problem, which if I solve in the way I know how, causes another problem.
    When I iterate in a positive direction--i++--the first instance of the text (in this example "abc") is correctly tagged. But the second instance the tag recedes by two characters, that is, tags the three characters prior to the "c." A third instance will recede two more characters, ad nauseam, if my Latin is correct.
    The solution is to iterate backwards, i.e., i--. But this causes another problem. If there is more than one story, then the xml structure reverses the order of the stories. The elements within a story are ordered correctly however.
    So why is this happening and how can I solve it?
    Thanks,
    Tom
    var myDoc = app.activeDocument;
    var findABC = theTextFinder(myDoc,"abc");
    xmlTagIt(myDoc,"abc",UIColors.RED,findABC);
    //*****functions*******
    function xmlTagIt(docRef, tagName,colorOfTag, arrToTag){
        var tagName, colorOfTag,  arrToTag;
        myDoc.xmlViewPreferences.showStructure = true;
        myDoc.xmlViewPreferences.showTaggedFrames =true;
        myDoc.xmlViewPreferences.showTagMarkers = true;
        myDoc.xmlViewPreferences.showTextSnippets =false;
        myDoc.xmlPreferences.defaultStoryTagColor = UIColors.WHITE;
        var rootElement = myDoc.xmlElements.item(0);
        if (myDoc.xmlTags.item(tagName) == null) {
            var tagRef = myDoc.xmlTags.add(tagName, colorOfTag);
      } else {//if tag already exists then stop the script. Avoid double tagging
           myDoc.xmlViewPreferences.showStructure = true;
           alert("You have already run this script.");
           exit();
       }//end else
        //for (var i = arrToTag.length-1; 0 <= i; i--){
        for (var i = 0; i <= arrToTag.length-1;  i++){
            var elementRef = rootElement.xmlElements.add (tagRef,arrToTag[i]);       
         }//end for i
    }//end function xmlTagIt
    function theTextFinder(docRef,textFindIt){//last argument is the string of text to find
        app.findTextPreferences = NothingEnum.NOTHING;
        app.changeTextPreferences = NothingEnum.NOTHING;
        app.findTextPreferences.findWhat = textFindIt;
        var arrTextFindIt = myDoc.findText();
        return arrTextFindIt;
    }//end theTextFinder

    Dave,
    Thanks for the reply.
    I'm not sure what you mean by "convert the references on the fly." You mean find a way to advance two characters forward and tag that? In the script I submitted here I am only searching for "abc," which of course I would not search or at all  in real life. The script uses grep to search for about twenty different typographical errors that typically appear and tags them all.
    Reiterating backwards seems, at first sight the way to go. But I haven't a clue as to how to reverse the order of the stories. I can get an array of stories, and array.reverse() them, but am not sure how to then make the script put this reversed order into the xml structure. Any hints?
    There, of course is bigger problem with the stories. If the document is written with one story created after another then the order of them is top to botom. But if say a text frame edited into the middle of all this, that story is still the last one in the xml structure. At least in one test, that was so. Maybe the way to solve this is to build an array of stories that have as one xml attribute the page it first appears on. Then order the array according to that attribute.
    Any advice you give will be appreciated.
    Thanks,
    Tom

  • Problem with iteration of Sprite objects?

    Hi all,
    I have an image on the stage, which is converted into a
    movieclip. When I click on this image, a pop-up with "Add-Note"
    hyperlink and a "Cancel_btn" appears. On clicking "Add-Note",
    allows us to enter/add a note(some text) specific to the pixel
    position(dot). A dot is a small circle(say, a dot)should
    appear(visible) on the same image at (x,y) pixel position when a
    note is added.
    Then, I need to add a Mouse_CLICK EventListener to this dot
    in such a way that, it must show some information (say, notes(viz.
    Note1,Note2,...etc.,),which contains some text information already
    entered in Text-boxes)when I click on specific dot.
    Since, dot must accept Mouse_CLICK event, I took it as a
    Sprite type of object.
    In this way I can add several dots and can handle
    Mouse_click events on a specific dot, only notes that are specific
    to the dot on which Mouse_CLICK event occured must be shown(Not all
    the notes of all the dots).
    The above explained is shown by the code attached to this topic.
    The problem is: I am unable to make visible the specific
    notes when I click on specific dot.
    So, I got struck up on visibility of specific dots for a
    specific user. I am unable to get them. Please reply me if you have
    solution to this issue.
    I will be waiting for the replies.

    Have a look at this:
    Transport connection -  cannot select infoobject (tick box)
    Regards

  • Problem in Iterating using logic:iterate tag

    Hi ,
    I am using <logic:iterate> tag to iterate through a list of contents.
    When the List size is 1222, all the Contents in the List are displaying properly.
    When the size execdes 1223, the JSP is not displaying properly.
    I am not getting any exception also.
    I have added try and catch. Still it is not showing any exception.
    When the size is more than 1300, Some contents are not displaying in JSP.
    Can any one provide some inputs, so that I can crack my issue.
    The JSP code :
              <logic:iterate id="someXXXX" property="someXXX" name="someXXX" indexId="count" scope="request">
              <tr>
    <td><html:text name="someXXXX" property="someXXXX"
                             size="50" maxlength="50" onchange="setDirty()" indexed="true"/> </td>               
    <td height="15" align="center"><html:checkbox property="someXXXX" name="someXXXX" indexed="true" onclick="setCheckboxFlag(this)" />               
                   <td width="4"> </td>               
              </tr>
              <html:hidden property="someXXXX" name="someXXXX" indexed="true" />
              </logic:iterate>
    Thanks,
    RamaKrishna

    get the records and store them in a collection. Store the collection in session. take the first 10 records as a subset and pass it to the iterate tag. use the hidden field to keep the last record number in the jsp. So when you first see the jsp the first 10 records will be shown and when user clicks for next records send the hidden field value to the server and take next 10 records as subset and pass it to iterate tag. This is how you can do this. but if you have thousands of records storing them in the session is not recommended. you can pull them directly from the database.

  • Checking an object in Arraylist against empty string

    Hi all,
    Im storing a collection of objects in Arraylist.Among them , one of the objects has an empty string.How can i check whether an object contains empty string.I tried to check using the follwing snippet:
    ArrayList idList=new ArrayList();
    if((idList.get(0)) == null || idList.get(0) == "")
            Debug.log("*****ARRAY LIST IS BLANK 1********");Please help

    Here is a bit more deeper code:
    HashMap lookupMap= null;
    try {
              Object obj = util.lookUp(pid,attributeId,params); // The lookUp method returns an object.
                 Debug.log(11, " obj type: " + obj.getClass().getName());
            lookupMap = (HashMap) obj;
    Collection mapkeys = lookupMap.keySet();
    Iterator itKeySet = mapkeys.iterator();
    ArrayList idList = new ArrayList();
    ArrayList descList = new ArrayList();
    ArrayList lookupKeys = new ArrayList();
    while(itKeySet.hasNext())
            lookupKeys.add(itKeySet.next());
    for(int i=0; i<lookupKeys.size(); i++)
            String key = (String)lookupKeys.get(i);
        if(key != null && key.startsWith("1_"))
              idList =(ArrayList)lookupMap.get(lookupKeys.get(i));
            if(key != null && key.startsWith("2_"))
              descList=(ArrayList)lookupMap.get(lookupKeys.get(i));
            if(key != null && key.startsWith("1_") && (size == 1))
               descList=(ArrayList)lookupMap.get(lookupKeys.get(i));
    ArrayList id1=new ArrayList();
    int x=0;
          do
         if(!(idList.get(x)).equals(null) || !(idList.get(x)).equals(""))
                    id1.add(idList.get(x));
                    Debug.log("*****idList.get(x)********"+idList.get(x));
                    Debug.log("*****added to idlist.get(0)********");
                    break;
                  else
                    x++;
         }while(id1.size() == 0);

  • Problems in Opening same jspx in different modes based on user selection

    Hello,
    I'm using JDeveloper 11.1.1.4.0
    Following is my use case and problems with each of the solutions that I have tried so far.
    1. Screen1 displays 4 af:tables. Right cilck of each table is a separate context sensitive menu.
    2. Using context sensitive menu items, user should open ReplyScreen and ConfirmScreen. Each of these screens support different functinoality however,
    they share quite a few common fields and functionality (variables).
    3. User should be allowed to work with each of the screens simultaneously.
    4. For simplicity, only 'Reply' and 'Confirm' modes are mentioned. However there are going to be 3 additional modes such as 'Correct', 'View' and 'Delete'.
    From code maintenability perspective, each of the 'Mode' specific screens should be a result of a single JSPX and bean.
    Solutions tried:
    1. Create a single JSP. Maintain the common variables in session.
    Problem: When user opens ReplyScreen, common variables are initialized. However, when he opens ConfirmScreen without closing ReplyScreen, common variables
    get overwritten.
    2. Create a single JSP. Maintain the common variables in Iterator, along with all the values fetched from DB.
    Problem: Same iterator object is shared amongst both pages.
    Question:
    1. How to create a single JSPX and attach each of its 'modes' (ReplyScreen and ConfirmScreen) to different Iterator objects?
    Any help will be appreciated...
    Thanks,
    Rohit
    Edited by: rohit6699 on Nov 18, 2011 1:15 AM
    Added tags

    Try creating a bounded taskflow that relies on parameters to define what it shows and how it behaves.
    The taskflow can use its own memory and transaction scope as needed and therefor you should be able to have multiple instances of it open with different behaviors.
    Learn more about taskfllows and regions here:
    http://www.oracle.com/technetwork/developer-tools/adf/learnmore/adfinsider-093342.html#a2

  • Problem in IterationTag

    Hi All,
    My afterBodyBody method is not working can any one help,
    i am not getting the output..
    Actually my problem was when we input two number through tag libs i want
    to find the power....
    ie-- input 2 numbers num1 = 3; num2 = 3;
    i want the result is 3 power 3 = 27.
    Actuall there is no Problem in web.xml file or tadlibEx.tld file
    because my remaining taglibs are working fine only i am having problem in
    iteration body .........i want a loop
    my powerEx.java
    package tagEx;
    import javax.servlet.jsp.*;
    import javax.servlet.jsp.tagext.*;
    public class powerEx implements IterationTag {
         private int number;
         private int power;
         private int result = 1;
         private int temp = 1;
         private PageContext p;
         private Tag t;
         public void setNumber (int number) {
              this.number = number;
         public void setPower (int power) {
              this.power = power;
         public powerEx () {
              super ();
         public void setPageContext (PageContext p) {
              this.p = p;
         public void setParent (Tag t) {
              this.t = t;
         public Tag getParent () {
              return t;
         public void release () { }
         public int doStartTag () {
              if (temp <= power) {
                   return EVAL_BODY_INCLUDE;
              else {
                   return SKIP_BODY;
         public int doAfterBody () throws JspException {
              try {
                   if (temp <= power) {
                        result = result * number;
                        temp++;
                        return EVAL_BODY_AGAIN;
                   else {
                        return SKIP_BODY;
              catch(Exception e) {
                   throw new JspTagException("IO Error: " + e.getMessage());
         public int doEndTag () throws JspException {
              try {
                   JspWriter out = p.getOut();
                   out.write("Hi the Result of number#### " + number + " power#### " + power + " is " + result);
              catch(java.io.IOException e) {
                   throw new JspTagException("IO Error: " + e.getMessage());
              return EVAL_PAGE;
    my jsp where i am using taglibs
    tagEx.jsp
    <%@ taglib uri="myTagUri" prefix="my" %>
    <HTML>
    <HEAD>
    <TITLE>Custom Tag Example!</TITLE>
    </HEAD>
    <BODY BGCOLOR="#FFFFFF">
         <%! int number1;
              int number2;
              String name;
         %>
         <%     number1 = Integer.parseInt (request.getParameter ("number1"));
              number2 = Integer.parseInt (request.getParameter ("number2"));
              name = request.getParameter ("name");
         %>
    <HR>Power is:<my:myTagPower number = '<%= number1 %>' power = '<%= number2 %>'/><HR>
    </BODY>
    </HTML>
    taglibEx.tld
    <?xml version="1.0" encoding="ISO-8859-1" ?>
    <!DOCTYPE taglib
         PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN"
         "http://java.sun.com/j2ee/dtd/web-jsptaglibrary_1_2.dtd">
    <taglib>
         <tlib-version>1.0</tlib-version>
         <jsp-version>1.2</jsp-version>
         <short-name>simple</short-name>
         <uri>http://jakarta.apache.org/tomcat/example-taglib</uri>
         <description>
              A simple tab library for the examples
         </description>
         <tag>
              <name>myTag</name>
              <tag-class>tagEx.helloTag</tag-class>
              <description> Display JSP sources </description>
         </tag>
    <tag>
              <name>myTagPower</name>
              <tag-class>tagEx.powerEx</tag-class>
              <description> Display JSP sources </description>
              <attribute>
                   <name>number</name>
                   <required>true</required>
                   <rtexprvalue>true</rtexprvalue>
              </attribute>
              <attribute>
                   <name>power</name>
                   <required>true</required>
                   <rtexprvalue>true</rtexprvalue>
              </attribute>
         </tag>
    </taglib>
    web.xml file is also fine
    <taglib>
    <taglib-uri>
                   myTagUri
    </taglib-uri>
    <taglib-location>
    /WEB-INF/sureshtaglibs/taglibEx.tld
    </taglib-location>
    </taglib>

    It states quite clearly in the API: The doAfterBody method is not invoked if there is no body evaluation.
    Your tag has an empty body, therefore no iteration takes place.
    If you change the tag in your JSP to HAVE a body, it works fine
    ie:
    <my:myTagPower number = '<%= number1 %>' power = '<%= number2 %>'>abc</my:myTagPower>
    Cheers,
    evnafets

  • Updating the arrayList

    Hi All,
    I hv a problem while using ArrayList.
    I have a glboal arrayList say gblList which contains all the elements fetched from database.
    There are two other local arrayLists(lclList1, lclList2) which are subset of gblList.
    I hae sorted lclList1, lclList2 independently based on a key. Now i have two sorted local arraylists.
    My requirement is : I have to update these sorted data of two local lists to gblList.
    could anyone pl help me!
    i wud be thankful to u..

    My requirement is : I have to update these sorted data
    of two local lists to gblList.First of all gblList will not be sorted. What you can get is the elements from IclList1, followed by the elements from IclList2, followed by the rest of the elements neither in IclList1 nor in IclList2. If some elements in IclList1 and IclList2 contains the same elements, gblList will contain doubles. Why would you want this strange ordering?

  • How to use Multimaps (Map String, ArrayList String )

    I was using an array to store player names, userIDs, uniqueIDs, and frag counts, but after reading about multimaps in the tutorials, it seems that would be much more efficient. However, I guess I don't quite understand it. Here's how I wanted things stored in my string array:
    String[] connectedUsers = {"user1_name", "user1_userid", "user1_uniqueid", "user1_frags"
                                            "user2_name"...}and here is how I'm attempting to setup and use the 'multimap':
    public class Main {
        static Map<String, ArrayList<String>> connectedUsers;
        public void updatePlayers(String name, String status) {
            String[] statusSplit = status.split(" ");
            if (connectedUsers.containsKey(name)) {
                connectedUsers.put(name, statusSplit[0]);
            else {
                connectedUsers.put(name, statusSplit[0]);
        }It's quite obvious I don't understand how this works, but should I even set this multimap up this way? Perhaps I should use a regular map with a string array for the values?

    You're cool MrOldie. Its just that alarm bells start ringing in my head when people come on and post as much as you do.
    * Created on Jul 28, 2005 by @author Tom Jacobs
    package tjacobs;
    import java.util.ArrayList;
    import java.util.Collection;
    import java.util.HashMap;
    import java.util.Iterator;
    import java.util.LinkedList;
    import java.util.Map;
    import java.util.Set;
    import java.util.TreeSet;
    * ManyMap is a map that allows more than one value to be stored with any key
    * <p>
    * There are a number of methods in the class that have been deprecated because
    * the original functionality of Map has been violated to accomodate the concept
    * of the ManyMap
    public class ManyMap<T, T2> implements Map<T, T2> {
         private HashMap<T, ArrayList<T2>> mInnerMap;
         public ManyMap() {
              mInnerMap = new HashMap<T, ArrayList<T2>>();
          * @deprecated
         public T2 get(Object obj) {
              ArrayList<T2> ar = _get(obj);
              if (ar == null || ar.size() == 0) {
                   return null;
              return ar.get(0);
         public Iterator<T2> getAll(Object obj) {
              ArrayList<T2> ar = _get(obj);
              if (ar == null || ar.size() == 0) {
                   return null;
              return ar.iterator();          
         public T2 put(T obj1, T2 obj2) {
              ArrayList<T2> ar = _getNotNull(obj1);
              ar.add(obj2);
              return obj2;
         public Set<Map.Entry<T, T2>> entrySet() {
              TreeSet<Map.Entry<T, T2>> entries = new TreeSet<Map.Entry<T, T2>>();
              Iterator<T> _i = mInnerMap.keySet().iterator();
              while (_i.hasNext()) {
                   T key = _i.next();
                   Iterator<T2> vals = mInnerMap.get(key).iterator();
                   while (vals.hasNext()) {
                        Entry<T, T2> entry = new Entry<T, T2>(key, vals.next());
                        entries.add(entry);
              return entries;
         public int size() {
              return mInnerMap.size();
         public int valuesSize() {
              int vals = 0;
              Iterator<T> _i = mInnerMap.keySet().iterator();
              while (_i.hasNext()) {
                   T key = _i.next();
                   ArrayList<T2> ar = mInnerMap.get(key);
                   vals += ar.size();
              return vals;
         public void clear() {
              mInnerMap.clear();
         public void putAll(Map<? extends T, ? extends T2> map) {
              Iterator _i = map.entrySet().iterator();
              while(_i.hasNext()) {
                   Map.Entry<? extends T, ? extends T2> entry = (Map.Entry<? extends T, ? extends T2>) _i.next();
                   put(entry.getKey(), entry.getValue());
         public Collection <T2> values() {
              LinkedList ll = new LinkedList();
              Iterator<ArrayList<T2>> _i = mInnerMap.values().iterator();
              while (_i.hasNext()) {
                   ll.addAll(_i.next());
              return ll;
         public boolean containsValue(Object val) {
              Iterator<ArrayList<T2>> values = mInnerMap.values().iterator();
              while (values.hasNext()) {
                   if (values.next().contains(val)) return true;
              return false;
         public boolean containsKey(Object key) {
              return mInnerMap.containsKey(key);
         public T2 remove(Object obj) {
              Iterator<ArrayList<T2>> values = mInnerMap.values().iterator();
              boolean found = false;
              while (values.hasNext()) {
                   if (values.next().remove(obj)) {
                        found = true;
              return found ? (T2)obj : null;
         public boolean isEmpty() {
              return valuesSize() == 0;
         @SuppressWarnings("hiding")
         private class Entry<T, T2> implements Map.Entry<T, T2> {
              T key;
              T2 val;
              public Entry (T obj1, T2 obj2) {
                   key = obj1;
                   val = obj2;
              public T2 getValue() {
                   return val;
              public T getKey() {
                   return key;
              public T2 setValue(T2 obj) {
                   return val = obj;
         public Set<T> keySet() {
              return mInnerMap.keySet();
         public ArrayList<T2> _get (Object obj) {
              return mInnerMap.get(obj);
         public ArrayList<T2> _getNotNull (T obj) {
              ArrayList<T2> list = _get(obj);
              if (list == null) {
                   list = new ArrayList<T2>(1);
                   mInnerMap.put(obj, list);
              return list;
    }Edited by: tjacobs01 on Aug 19, 2008 12:28 PM

Maybe you are looking for

  • Can I update 2(or multiple) columns in a table based on one of update col?

    Hi All, I have a table emp: empno number ,salary number ,comm number Now, the comm column is always a % of the salary column (but still would like to store the comm in the table as a column). Assuming that someone get a salary increment and I need to

  • ALV Page Break when Catagory Changes (ie SO # change)

    I will have an ALV report with a Sale Order # on a header section and line items associated for the header SO#, and when a different SO# occurs it will go to next page and display the next SO# on header section and the item info on the main body.  Is

  • Problem in Call Statement

    Hi Experts, in following code what is 'ThNoGet' . Please let me know haow to find it? CALL 'ThNoGet' ID 'BNRIV'    FIELD BNRIV                  ID 'NO'       FIELD G_NOIVBUFFER                  ID 'QUAN'     FIELD P_QUANTITY                  ID 'PERC

  • Bootcamp: Sound not working on Windows Vista Ultimate 32-bit

    Hello everyone, I've got quite an unsual problem (whell at least I think anyway). On my iMac (Mid 2008, 2.4Ghz C2D, 2GB ram, 2400XT), I recently installed Windows Vista Ultimate (32 bit). I've been using the sound out of the speakers, until now when

  • Unable to reclaim free space

    tablespace size: 62G, 14 4G files and 1 6G file, freespace =51G When I try to resize datafiles, I get an error; the max free space per file =1G --- not sure what is using up the space. environment: 10.2.0.3 2-node RAC cluster on Red Hat Linux 4 Can s