Private static ArrayList within java.util.Arrays

I was recently reviewing the code in java.util.Arrays (class version 1.45 - Java version 1.4.1). Beginning on line 2289 is a private static class named ArrayList. I'm completely baffled as to why the author created this slimmed-down private class (which would be, incidentally, returned by the Arrays.asList(Object[] a) method) rather than use the public class java.util.ArrayList. Can anyone offer an explanation?
Thanks,
John

from JDK JAVADoc:
asList
public static List asList(Object[] a)
Returns a fixed-size list backed by the specified array. (Changes to the returned list "write through" to the array.) This method acts as bridge between array-based and collection-based APIs, in combination with Collection.toArray. The returned list is serializable.
So the private ArrayList extends java.util.ArrayList, and any changes made this list does not affect the internal Object[].... in other words can not be changed.

Similar Messages

  • Error: java.lang.ClassCastException: java.util.Arrays$ArrayList

    Hi,
    How to solve this error?
    I get the error at this line of code in my program.
    java.util.ArrayList list= (java.util.ArrayList)obj;
    Please help how to solve this problem.
    Thanks,
    cmbl

    cmbl wrote:
    How to solve this error?
    I get the error at this line of code in my program.
    java.util.ArrayList list= (java.util.ArrayList)obj; Don't do this cast.
    Why are you doing this cast anyway? I think you need to show a small bit of compilable code (or almost compilable except perhaps for this error) and some more explanation.

  • Trouble extending java.util.Arrays

    I have written some utility functions for dealing with arrays and I would like to bundle them into a class along with java's built-in array functions (java.util.Arrays). To do this, I tried to extends the class java.util.Arrays like this:
    public class ArrayUtils extends java.util.Arrays
    /* some static methods */
    When I try to compile this with javac (even with no class body between the braces), I get an error "error:Cannot find constructor "Arrays" with matching parameters [JLS 15.12]". Does anyone know what's going on here? Why is the compiler looking for a constructor? And why can't it find one? I would very much appreciate your insight. Thanks. Eli

    Does anyone know what's
    going on here? Why is the compiler looking for a
    constructor? And why can't it find one?Conceputually....
    Inheritance exists to allow one to inherit from an object. In java objects can be created by using a class. However classes in java do not have to be objects. And you are trying to inherit from something that is not an object.
    One of the other uses for class in java is to group a number of convienent functions together. (Grouped functions do NOT represent a class.) That is what java.util.Arrays is.
    Technically....
    The class java.util.Arrays has a private constructor which means you can't derive anything from it.

  • Using java.util.Arrays.binarySearch

    Hi,
    I tried the following code
    import java.util.Arrays ;
    class SecondTry {   
    public static void main(java.lang.String args[]) {
    int xyz[] = new int[10];
    xyz[0] = 5;
    xyz[1] = 6;
    xyz[2] = 1;
    Arrays.sort(xyz);
    System.out.println(Arrays.binarySearch(xyz,5));
    i expected to see a result of 1. But i get a 8.
    I am sure i must be doing something wrong. But not able to figure out what exactly is wrong. Could somebody help?
    TIA,
    Babu

    hi there,
    .The output was 8 because u have declared the array size to be 10,so the values which are not assigned would be assigned to zero,so if you change the array size to 3,u would get the desired output :)
    cheers
    class SecondTry {
    public static void main(java.lang.String args[]) {
    int xyz[] = new int[3]; //change to three
    xyz[0] = 5;
    xyz[1] = 6;
    xyz[2] = 1;
    Arrays.sort(xyz);
    System.out.println(Arrays.binarySearch(xyz,5));

  • Why the Error in ArrayList Program : java.util.NoSuchElementException

    import java.util.List;
    import java.util.ArrayList;
    import java.util.Iterator;
    import java.util.ListIterator;
    import java.util.Collections;
    import java.util.Random;
    public class ArrayListDoubt {
        public static void main(String[] args) {
    //        ArrayList Creation
            List arraylistA = new ArrayList();
            List arraylistB = new ArrayList();
    //        Adding elements to the ArrayList
            for (int i = 0; i < 5; i++) {
                arraylistA.add(new Integer(i));
            arraylistB.add("beginner");
            arraylistB.add("java");
            arraylistB.add("tutorial");
            arraylistB.add(".");
            arraylistB.add("com");
            arraylistB.add("java");
            arraylistB.add("site");
    // Iterating through the ArrayList to display the Contents.
            Iterator i1 = arraylistA.iterator();
            System.out.print("ArrayList arraylistA --> ");
            while (i1.hasNext()) {
                System.out.print(i1.next()+ " , ");
            System.out.println();
            System.out.print("ArrayList arraylistA --> ");
            for (int j=0; j < arraylistA.size(); j++) {
                System.out.print(arraylistA.get(j)+ " , ");
            System.out.println();
            Iterator i2 = arraylistB.iterator();
            System.out.println("ArrayList arraylistB --> ");
            while (i2.hasNext()) {
                System.out.print(i2.next()+ " , ");
            System.out.println();
            System.out.println("Using ListIterator to retireve ArrayList Elements");
            System.out.println();
            ListIterator li = arraylistA.listIterator();
    //       next(), hasPrevious(), hasNext(), hasNext() nextIndex() can be used with a
    //        ListIterator interface implementation
            System.out.println("ArrayList arraylistA --> ");
            while (li.hasNext()) {
                 System.out.print(i1.next()+ " , ");
    Output
    ArrayList arraylistA --> 0 , 1 , 2 , 3 , 4 ,
    ArrayList arraylistA --> 0 , 1 , 2 , 3 , 4 ,
    ArrayList arraylistB -->
    beginner , java , tutorial , . , com , java , site ,
    Using ListIterator to retireve ArrayList Elements
    ArrayList arraylistA -->
    Exception in thread "main" java.util.NoSuchElementException
         at java.util.AbstractList$Itr.next(AbstractList.java:427)
         at ArrayListDoubt.main(ArrayListDoubt.java:58)

    System.out.println("Using ListIterator to
    retireve ArrayList Elements");
    System.out.println();
    ListIterator li = arraylistA.listIterator();
    next(), hasPrevious(), hasNext(), hasNext()
    nextIndex() can be used with a
    /        ListIterator interface implementation
    System.out.println("ArrayList arraylistA -->
    while (li.hasNext()) {
         System.out.print(i1.next()+ " , ");
    }I think you mean to call the next()-method of the ListIterator li, but instead call i1, which is an already used Iterator.
    Where you want to iterate with ListIterator, change this line
    System.out.print(i1.next()+ " , ");to this
    System.out.print(li.next()+ " , ");and it works

  • Java.util.Arrays.sort for Vector

    I used the java.util.Arrays.sort to sort an array based on the method below.
                  java.util.Arrays.sort(array, 0, total, new ComparatorX());
               repaint();
                class ComparatorX implements java.util.Comparator
              public int compare( Object p1, Object p2){
                   int x1=((Point)p1).x;
                   int x2=((Point)p2).x;
                   if(x1>x2)
                                return 1;
                   if(x1>x2)
                                return -1;
                   return 0;
         }I've since changed the array to a vector. Is there anyway I can keep the comparator. Or how can I sort the vector based on the above method.

    BTW: Don't know if it's just a typing mistake, but your code contains an error:
    class ComparatorX implements java.util.Comparator     {
       public int compare( Object p1, Object p2) {
          int x1=((Point)p1).x;
          int x2=((Point)p2).x;
          if (x1>x2) {
             return 1;
          if (x1>x2) {  // Should be: if (x2 > x1) ...
             return -1;
          return 0;

  • How to set property "java.util.Arrays.useLegacyMergeSort" in jnlp-file?

    Hi,
    I have a problem in a web start application with java 7 and the new sort behavior (exception: comparison method violates its general contract).
    So I like to go back to previous behavior and tried to put the new java 7 system property "java.util.Arrays.useLegacyMergeSort" in the generated jnlp-File:
    <property name="java.util.Arrays.useLegacyMergeSort" value="true"/>.
    Now I can read the property value in java code with System.getProperty("java.util.Arrays.useLegacyMergeSort"), and guess the property was successful set, but the exception still appears?!
    The system property works with command line "javaws -J-Djava.util.Arrays.useLegacyMergeSort=true file.jnlp", but not via doubleclick on the jnlp-file or url and browser.
    Any ideas?
    Cheers,
    Dan

    Only "trusted" set of properties can be set in the JNLP file by unsigned applications.
    List of properties is revised from time to time but it usually takes time for new properties to be added to it (if there is strong demand for it as every property should undergo security audit).
    You can specify arbitrary property if you sign your application and JNLP file.

  • Java.util.Array

    Exception in thread "main" java.lang.ClassCastException: Card
    at java.util.Arrays.mergeSort(Arrays.java:1044)
    at java.util.Arrays.sort(Arrays.java:997)
    at CardPlayer.sortHand(CardPlayer.java:91)
    at Game.main(Game.java:75)
    i get this error message after I call a sort method using the java.util.Array
    does anyone know why, or do u need more code?
    thanks

    The Card object needs to implement the Comparable interface if an array of them is to be sorted. The ClassCastException occurs when the sorting code attempts to assign a Card Object to a Comparable variable. The API documentation refers to this problem like this:
    Throws:
    ClassCastException - if the array contains elements that are not mutually comparable (for example, strings and integers).

  • AsList(java.lang.Object[]) in java.util.Arrays cannot be applied to (int[])

    hi all,
    i'm getting the above error msg when trying to compile a simple array prog...
    while at it, is there another simple way to print the contents
    of an array to the console in a single statement except using the asList method??? .. like :
    int[] myArray = {1,2,3,4};
    System.out.println(myArray);
    ==================================
    here's the code for my program :-
    tks in advance.
    import java.util.*;
    public class ListArray {
    public static void main(String args[]) {
         int[] anArray = {2,7,5,8,3};
         for (int i = 0; i < anArray.length; i++) {
         System.out.println("Element No : " + (i+1) + " = " + anArray);
         System.out.println("All the Elements : " + Arrays.asList(anArray));

    Funnily enough, thats because int[] is not an array of Objects.
    You can make your listing method work by writing this instead:
    for (int index = 0; index < anArray.length; index++) {
      System.out.println("Element No: " + (index + 1) + " = " + anArray[index]);
    }

  • Java.util.Arrays; (method sort( ) )

    1) How to change a direction of sorting (on increase / on decrease)?
    2) Whether exists in java 2 something similar for sorting Strings ?

    1) How to change a direction of sorting (on increase
    / on decrease)?[url http://java.sun.com/j2se/1.5.0/docs/api/java/util/Collections.html#reverseOrder()]http://java.sun.com/j2se/1.5.0/docs/api/java/util/Collections.html#reverseOrder()
    2) Whether exists in java 2 something similar for
    sorting Strings ?Arrays.sort and Collections.sort will both sort the array or list as long as the type implements Comparable (or you supply a separate Comparator). Since String implements Comparable, those sort methods will sort the array or list of strings.
    Making Java Objects Comparable
    http://java.sun.com/docs/books/tutorial/collections/interfaces/order.html
    http://www.javaworld.com/javaworld/jw-12-2002/jw-1227-sort.html

  • Question on import java.util.ArrayList, etc.

    Hi,
    I was wondering what the following meant and what the differences were. When would I have to use these:
    import java.util.ArrayList;
    import java.util.Collections; <--I especially don't understand what this means
    import java.util.Comparator; <---same for this (can I consolidate these into the bottom two?)
    import java.io.*;
    import java.util.*;

    MAresJonson wrote:
    Also, what does this mean:
    return foo == f.getFoo() ? true : false;
    (more specifically...what does the "? true : false" mean and is there another way to code that?)It's called the ternary operator. For your specific example, you could just do:
    return foo == f.getFoo();But, more generally,
      return foo == f.getFoo() ? "equal" : "Not equal";means:
    if (foo == f.getFoo()) {
       return "equal";
    else {
       return "Not equal";
    }As everyone else said at the same time...

  • Issue with h:selectManyListBox - java.util.NoSuchElementException

    I facing an issue with <h:selectManyListBoxs in JSF 1.1 with portlets.
    I am using RAD 7.5.3 and server is Web sphere Portal v6.1 Server on WAS 7.
    I have two <h:selectManyListbox moving options from Left to Right which i am doing in Javascript and it is perectly working fine.
    For the right hand side list box i have an additional movement for up and down which i am doing in javascript and it is working fine.
    Now the issue when I move from left to right and click on Save it is working fine. when I try to touch/select the options
    in right hand side list box and click on save i am getting NoSuchElementException in the processValidation phase as shown below.
    (It is not calling the save function at all in this case, it just calling the getLinkedBenchmarks method and failing).
    I added the attribute as immediate= true and the exception is comming now in APPLY_REQUEST phase.
    JSF1054: (Phase ID: PROCESS_VALIDATIONS 3, View ID: /jsp/Test.jsp) Exception thrown during phase execution:
    javax.faces.event.PhaseEvent[source=com.sun.faces.lifecycle.LifecycleImpl@32fc32fc]
    Caused by: javax.portlet.PortletException
         at com.ibm.faces.portlet.FacesPortlet.processAction(FacesPortlet.java:199)
         at com.ibm.ws.portletcontainer.invoker.impl.PortletFilterChainImpl.doFilter(PortletFilterChainImpl.java:77)
         at com.ibm.wps.propertybroker.standard.filter.PropertyBrokerActionFilter.doFilter(PropertyBrokerActionFilter.java:731)
    Caused by: java.util.NoSuchElementException
         at javax.faces.component.SelectItemsIterator.next(SelectItemsIterator.java:128)
         at javax.faces.component.SelectItemsIterator.next(SelectItemsIterator.java:175)
         at javax.faces.component.SelectItemsIterator.next(SelectItemsIterator.java:60)
         at javax.faces.component.UISelectMany.matchValue(UISelectMany.java:497)
         at javax.faces.component.UISelectMany.validateValue(UISelectMany.java:466)
         at javax.faces.component.UIInput.validate(UIInput.java:875)
         at javax.faces.component.UIInput.executeValidate(UIInput.java:1072)
         at javax.faces.component.UIInput.processValidators(UIInput.java:672)
         at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1047)
         at javax.faces.component.UIForm.processValidators(UIForm.java:235)
         at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1047)
         at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1047)
         at javax.faces.component.UIViewRoot.processValidators(UIViewRoot.java:673)
         at org.ajax4jsf.framework.ajax.AjaxViewRoot.access$201(AjaxViewRoot.java:53)
         at org.ajax4jsf.framework.ajax.AjaxViewRoot$3.invokeRoot(AjaxViewRoot.java:315)
         at org.ajax4jsf.framework.ajax.JsfOneOneInvoker.invokeOnRegionOrRoot(JsfOneOneInvoker.java:53)
         at org.ajax4jsf.framework.ajax.AjaxContext.invokeOnRegionOrRoot(AjaxContext.java:191)
         at org.ajax4jsf.framework.ajax.AjaxViewRoot.processValidators(AjaxViewRoot.java:329)
         at com.sun.faces.lifecycle.ProcessValidationsPhase.execute(ProcessValidationsPhase.java:76)
         at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)
         at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
         at com.ibm.faces.portlet.FacesPortlet.processAction(FacesPortlet.java:189)
         ... 118 more
      JSP code: I tried to add value for the <h:selectManyList it only allowing to add String not Arrays it displays the following warning
    message "Cannot coerce type String[] to java.lang.String"
    <h:selectManyListbox  size="10" id="availableBMId" converter="com.Converter"
         binding="#{lookup.components.availableBMId}" >
         <f:selectItems
              value="#{themeAttributeBean.availableBMs}" />
    </h:selectManyListbox></td>
    <td style="vertical-align: middle;">
    <div id="benchmark_button1" align="center"><hx:graphicImageEx
         id="Benchmark_AllRight" url="/images/AllRight.gif" height="16"
         hspace="2" style="cursor: hand" width="16" title="All Right"
         onclick="return listbox_moveall('#{lookup.clientIds.availableBMId}', '#{lookup.clientIds.linkedBMId}');">
    </hx:graphicImageEx> <br>
    <br>
    <hx:graphicImageEx id="Benchmark_Right" url="/images/Right.gif"
         height="16" hspace="2" style="cursor: hand" width="16" title="Right"                                                  
         onclick="return listbox_moveacross('#{lookup.clientIds.availableBMId}', '#{lookup.clientIds.linkedBMId}');">
    </hx:graphicImageEx> <br>
    <br>
    <hx:graphicImageEx id="Benchmark_Left" url="/images/Left.gif" title="Left"
         height="16" hspace="2" style="cursor: hand" width="16"                                                  
         onclick="return listbox_moveacross('#{lookup.clientIds.linkedBMId}', '#{lookup.clientIds.availableBMId}');">
    </hx:graphicImageEx> <br>
    <br>
    <hx:graphicImageEx id="Benchmark_AllLeft" title="All Left"
         url="/images/AllLeft.gif" height="16" hspace="2"
         style="cursor: hand" width="16"                                             
         onclick="return listbox_moveall('#{lookup.clientIds.linkedBMd}', '#{lookup.clientIds.availableBMId}');">
    </hx:graphicImageEx></div>
    </td>
    <td valign="top">
    <h:selectManyListbox size="10"
         id="linkedBenchmarksId" converter="com.TAPConverter"
         binding="#{lookup.components.linkedBMId}">
         <f:selectItems value="#{themeAttributeBean.linkedBMs}" />
    </h:selectManyListbox></td>
    <td style="vertical-align: middle;">
    <div id="benchmark_button2" align="center">
    <hx:graphicImageEx id="benchmark_up" url="/images/Up.gif" title="Up"
         height="16" hspace="2" style="cursor: hand" width="16"                                                  
         onclick="movePageUp('#{lookup.clientIds.linkedBMId}');"></hx:graphicImageEx>
    <br>
    <hx:graphicImageEx id="benchmark_down" url="/images/Down.gif" title="Down"
         height="16" hspace="2" style="cursor: hand" width="16"                                                  
         onclick="movePageDown('#{lookup.clientIds.linkedBMId}');"></hx:graphicImageEx>
    <br></div>
    *getting teh javascript values in a hiddend value:*
    <h:inputHidden id="hiddenLinkedBms"
    binding="#{lookup.components.hiddenLinkedBenchmarks}" value="#{bean.hiddenLinkedBms}" />
    *Backing Bean code:*
    public Map<String, Index> getAvailableBenchmarks() {
         availableBM = dao.getAllBM();
         if (themeID.intValue() > 0) {          
              linkedBM = dao.getLinkedBenchmarks(themeID.intValue());
              System.out.println("Linked Bench marks in getAvailableBM.. " + linkedBM);
              removeKeys(availableBM, linkedBM);
         return availableBM;
    public Map<String, Index> getLinkedBM() {
         linkedBenchmarks = dao.getLinkedBM(id);
         return linkedBM;
    Additional info:
         I override the equals and hashcode method in the Object class as suggested on the internet.
         I added the Custom converter by implementing javax.faces.convert.Converter and
         @Override
         public String getAsString(FacesContext arg0, UIComponent arg1, Object obj) {
              if(obj == null){
                   return null;
              } else if(obj instanceof Index){
                   final TAPIndex index = (Index) obj;
                   return index.getIndexName().toString();
              } else if(obj instanceof Objective){     
                   final InvestmentObjective invest = (Objective) obj;
                   return invest.getDescription()+" (" + invest.getCode() + ")".toString();
              return obj.toString();
         @Override
         public Object getAsObject(FacesContext arg0, UIComponent arg1, String value) {
                   return value;
    I have no Idea why it is behaving like this. Please help me.Edited by: Joglekar on Sep 17, 2010 10:17 AM

    Here is the proof - Let me know if am doing any thing wrong! FYI, I used JSF portlets in RAD 7.5.3 and Websphere portal server v6.1.
    I have two SelectManyListBox components and moving the options from left to right using Javascript and then select one of the options in the right hand side list box and click on submit. You will see the NosuchElementException.
    I don't have any logic inside my bean class in any of the methods.
    My Test JSP
    <%-- jsf:pagecode language="java" location="/.apt_generated/com/jsp/TestJSP.java" --%><%-- /jsf:pagecode --%><%@taglib
         uri="http://java.sun.com/portlet" prefix="portlet"%><%@taglib
         uri="http://www.ibm.com/jsf/html_extended" prefix="hx"%><%@taglib
         uri="http://java.sun.com/jsf/core" prefix="f"%><%@taglib
         uri="http://java.sun.com/jsf/html" prefix="h"%><%@page language="java"
         contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1" session="false"%><portlet:defineObjects />
    <f:view>
    <script language="javascript">
    function listbox_moveall(sourceID, destID) {
         var src = document.getElementById(sourceID); var dest = document.getElementById(destID);
         for(var count=0; count < src.length; count++) {
              var option = src[count];
              try {
                   dest.add(new Option(option.text, option.text), null); //Standard
                   src.remove(count, null);
              } catch(error) {
                   dest.add(new Option(option.text, option.text)); // IE only
                   src.remove(count);
              } count--;
         } return true;
    function listbox_moveacross(sourceID, destID) {
         var src = document.getElementById(sourceID); var dest = document.getElementById(destID);
         var selectedIndex = src.selectedIndex;
         if(selectedIndex == -1){
              alert("Please select to move");
         for(var count=0; count < src.length; count++) {
              if(src[count].selected == true) {
                   var option = src[count];
                   try {
                        dest.add(new Option(option.text, option.value), null); //Standard
                        src.remove(count, null);
                   } catch(error) {
                        dest.add(new Option(option.text, option.value)); // IE only
                        src.remove(count);
                   }  count--;               
    </script>
    <hx:scriptCollector id="scriptCollector1">
         <h:form styleClass="form" id="form1" prependId="false">
         <table BORDER="0" CELLPADDING="1" CELLSPACING="0" bgcolor="eeeeee">
              <tbody>
                   <tr> <td colspan="3"><b>TAP Investment Objectives</b></td> </tr>
                   <tr> <td bgcolor="#bfbfbf"><b>Available List</b></td>      <td width="65"></td>
                        <td bgcolor="#bfbfbf"><b>Linked List </b></td> </tr>
                   <tr><td valign="top">
         <h:selectManyListbox size="10" styleClass="selectManyListbox" id="listbox1">
                   <f:selectItems value="#{selectitems.testJSP.availableBMs.availableBMs.toArray}" id="selectItems2" />
         </h:selectManyListbox></td>
         <td style="vertical-align: middle;"> <div id="objective_button" align="center">
         <hx:graphicImageEx url="/images/AllRight.gif" title="All Right" height="16" hspace="2" width="16"
         onclick="return listbox_moveall('listbox1', 'listbox2');"></hx:graphicImageEx>      <br> </div> </td>
         <td valign="top">
              <h:selectManyListbox size="10" styleClass="selectManyListbox" id="listbox2" >
                   <f:selectItems value="#{selectitems.testJSP.linkedBMs.linkedBMs.toArray}" id="selectItems1" />
              </h:selectManyListbox>
         </td>
              </tr>
              </tbody>
         </table>
         <hx:commandExButton type="submit" value="Submit"
              styleClass="commandExButton" id="button1" action="#{testJSP.save}"></hx:commandExButton>
         </h:form>
    </hx:scriptCollector>
    </f:view>My Backing Bean Class
    package com.jpmorganchase.tap.ui.bean;
    import java.util.ArrayList;
    import java.util.List;
    import javax.faces.component.UIComponent;
    import javax.faces.event.ActionEvent;
    public class TestUIJSP {
         private List<String> availableBMs;
         private List<String> linkedBMs;
         private UIComponent selectedBindingBMs;
         public UIComponent getSelectedBindingBMs() {
              System.out.println("getSelectedBindingBMs .. " + selectedBindingBMs);
              return selectedBindingBMs;
         public void setSelectedBindingBMs(UIComponent selectedBindingBMs) {
              this.selectedBindingBMs = selectedBindingBMs;
         public TestUIJSP(){
              System.out.println("inside constructor...............");
              availableBMs = new ArrayList<String>();
              availableBMs.add("Venkat");
              availableBMs.add("Narayana");
              availableBMs.add("Joglekar");
              linkedBMs = new ArrayList<String>();
         public List<String> getAvailableBMs() {
              return availableBMs;
         public void setAvailableBMs(List<String> availableBMs) {
              this.availableBMs = availableBMs;
         public List<String> getLinkedBMs() {
              return linkedBMs;
         public void setLinkedBMs(List<String> linkedBMs) {
              this.linkedBMs = linkedBMs;
         public String save(){
              System.out.println("save availableBMs........." + availableBMs);
              System.out.println("save linkedBMs........." + linkedBMs);
              return null;
         public void moveAllLeftToRight(ActionEvent evt){
              System.out.println("availableBMs.." + availableBMs);
              linkedBMs.addAll(availableBMs);
              System.out.println("LinkedBM's");
              availableBMs.clear();
         public void moveLeftToRight(ActionEvent evt){
              System.out.println("availableBMs.." + availableBMs);
    }MyFaces Config.xml
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE faces-config PUBLIC "-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.0//EN" "http://java.sun.com/dtd/web-facesconfig_1_0.dtd">
    <faces-config>
         <application>
              <state-manager>com.ibm.faces.application.DevelopmentStateManager</state-manager>
              <property-resolver>com.ibm.faces.databind.SelectItemsPropResolver</property-resolver>
              <variable-resolver>com.ibm.faces.databind.SelectItemsVarResolver</variable-resolver>
              <variable-resolver>com.ibm.faces.portlet.PortletVariableResolver</variable-resolver>
              <locale-config><supported-locale>en</supported-locale></locale-config>
              <message-bundle>com.PortletResource</message-bundle>
         </application>
         <factory><faces-context-factory>com.ibm.faces.context.AjaxFacesContextFactory</faces-context-factory>
              <render-kit-factory>com.ibm.faces.renderkit.AjaxRenderKitFactory</render-kit-factory></factory>
         <managed-bean>
                <managed-bean-name>pc_TestJSP</managed-bean-name><managed-bean-class>com.jsp.TestJSP</managed-bean-class>
                   <managed-bean-scope>session</managed-bean-scope>
              </managed-bean><managed-bean>
              <managed-bean-name>testJSP</managed-bean-name><managed-bean-class>com.bean.TestUIJSP</managed-bean-class>
                   <managed-bean-scope>session</managed-bean-scope></managed-bean>
         <lifecycle>     <phase-listener>com.ibm.faces.webapp.ValueResourcePhaseListener</phase-listener></lifecycle>
    </faces-config>
    My Protlet.xml<?xml version="1.0" encoding="UTF-8"?>
    <portlet-app xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd" version="1.0" id="com.ibm.faces.portlet.FacesPortlet.c8eddc2f92">
         <portlet>
              <portlet-name>TestProject</portlet-name>
              <portlet-class>com.ibm.faces.portlet.FacesPortlet</portlet-class>
              <init-param><name>com.ibm.faces.portlet.page.view</name><value>/jsp/testJSP.jsp</value></init-param>
              <init-param><name>wps.markup</name><value>html</value></init-param>
              <expiration-cache>0</expiration-cache>
              <supports><mime-type>text/html</mime-type><portlet-mode>view</portlet-mode></supports>
              <supported-locale>en</supported-locale><resource-bundle>com.PortletResource</resource-bundle>
         </portlet>
    </portlet-app>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    

  • Import java.util Error

    How come program wont accept import java.util ?
    I get cannot resole symbol ?? i looked in up in my java book and its spelled right . what gives ?

    there is no class named java.util .
    import java.util.ArrayList;
    import java.util.EventObject;
    or
    import java.util.*;

  • Duration between 2 java.util.Dates

    Hi,
    Recently found a problem calculating duration between two dates. It has confused me as it happens only on certain dates!
    Notice the duration for 28/10/07 - outputs 85 minutes. Am I missing something obvious here?
    GregorianCalendar gc = new GregorianCalendar(2007,0,1);
            for(int i=0; i<365; i++) {
                String date = gc.get(Calendar.DATE) + "/" + (gc.get(Calendar.MONTH)+1) + "/" + gc.get(Calendar.YEAR);
                String dateVal1 = date + " 00:39";
                GregorianCalendar date1 = DateTime.toGregorianCalendar(dateVal1, "dd/MM/yy HH:mm");
                String dateVal2 = date + " 01:04";
                GregorianCalendar date2 = DateTime.toGregorianCalendar(dateVal2, "dd/MM/yy HH:mm");
                System.out.println(date + " - " + DateTime.calculateDuration(date1, date2));
                gc.add(Calendar.DATE, 1);
    public final static GregorianCalendar toGregorianCalendar(String date, String pattern) {
            SimpleDateFormat formatter = new SimpleDateFormat(pattern);
            GregorianCalendar gc1 = new GregorianCalendar();
            Date parsedTime = new Date();
            try {
                parsedTime = formatter.parse(date);
            } catch (ParseException ex) {
                ex.printStackTrace();
                return null;
            gc1.setTime(parsedTime);
            return gc1;
    public final static long calculateDuration(java.util.Date a, java.util.Date b) {
            Calendar earlier = Calendar.getInstance();
            Calendar later = Calendar.getInstance();
            if (a.compareTo(b) < 0) {      
                earlier.setTime(a);
                later.setTime(b);
            else {
                earlier.setTime(b);
                later.setTime(a);
            System.out.println(earlier.getTimeInMillis() + ":" + later.getTimeInMillis());
            long l1 = earlier.getTimeInMillis();
            long l2 = later.getTimeInMillis();
            return (int)(((l2-l1)/1000) / 60);
    }

    I asked someone in the office and its the first thing they said!!!!!!!!!!!!!!!
    So - now fixed and I know for next time.
    Thanks - the dukes are yours

  • What is the proper and best way to destroy a java.util.List or Array for GC

    Hi,
    If I have a java.util.List of objects lets say:
    List<File> files = new ArrayList();The List contains 1000 file objects. When my class finishes, is it enough to do
    files = null;to make GC able to release it from memory?
    Cause it seems like I can't do the following:
    for(int i = 0; i < extracted_files.size(); i++){
                extracted_files.get(i) = null;
    }Or should I use this one:
    files.clear()What is the proper and best way to do this in order to avoid memory leaks? How about normal Arrays like File[]?
    Edited by: TolvanTolvanTolvan on 2009-sep-10 16:58

    TolvanTolvanTolvan wrote:
    Thanks for the info!
    But what if the List is a class variable running in a Web Service for like months without terminating?You mean if the List variable is a member variable of a long-lived object? Then presumably the list needs to live as long as the object does. In the unlikely scenario that the object needs to live on but its list member variable does not, then yes, setting the member to null will be needed to make the list eligible for GC. But I highly doubt this is your situation, and if it is, you probably have a design flaw.
    And if the list is referenced only by a local variable, then, as I already said, when the method ends, the variable goes out of scope, and the List is eligible for GC.
    Now, a slightly different situation is when the List needs to live a long time, and at some point during its life, you're done using some object that it refers to. In that situation, simply remove the element from the list (or set the element to null if it's an array rather than a list), and then if it's not referenced anywhere else, it can be GCed.
    How about Arrays like File[]? Do I need to iterate through the array and null all the objects or is it enough to just null the Array?YOU. DON'T. NEED. TO. HELP. GC. You don't need to set the elements to null, and you most likely don't even need to set the array variable to null.
    Also note that only references can be null, not objects.

Maybe you are looking for