About Collections class

The Collections Framework defines several algorithms that can be applied to collections
and maps.These algorithms are defined as static methods within the Collections class.
These algorithms support List,Map,Set,Enumeration,SortedMap,SortedSet.But not
Iterator.
Is it fixed by Java that no Iterator can use within any of those algorithms of Collections
class?
Or, Is it only Maps class support Iterator for it's algorithms?

Thanks everybody for replies.
import java.util.*;
public class AlgorithmsDemo {
     public static void main(String[] args) {
          LinkedList<Integer> ll=new LinkedList<Integer>();
          System.out.println("Size of LinkedList ll: "+ll.size());
          System.out.println("Contents of LinkedList ll: "+ll);
          ll.add(-8);
          ll.add(20);
          ll.add(-20);
          ll.add(8);
          System.out.println("Now the size of linkedList ll: "+ll.size());
          System.out.println("Now the contents of linkedlist ll: "+ll);
          Comparator<Integer> comp=Collections.reverseOrder();
          Collections.sort(ll,comp);
          System.out.print("List sorted in reverse: ");
          for(int i:ll)
               System.out.print(i+" ");
          System.out.println();
          Collections.shuffle(ll);
          System.out.print("List shuffled: ");
          for(int i:ll)
               System.out.print(i+" ");
          System.out.println();
          System.out.println("Minimum: "+Collections.min(ll));
          System.out.println("Maximum: "+Collections.max(ll));
}If I want to use Iterator instead of Comparator then what changes need to do
within above code?

Similar Messages

  • Collection class comparation

    Dear all,
    Could you tell me the performance benmark comparation between the collection class (List, Map, Set, Queue, and also class in java.util.concurrent package...)
    Could you give me when to use one class?
    Thank a lot for support.
    Best regards,
    VKnight

    VKnight wrote:
    Dear all,
    Could you tell me the performance benmark comparation between the collection class (List, Map, Set, Queue, and also class in java.util.concurrent package...)There is no "fastest collection." Different collections have different big-O performance metrics in different situations. You'll learn what these are when you learn about the collections.
    Could you give me when to use one class? When you study the collections and learn what each one does, you'll understand which one is appropriate to use in which case.
    There's plenty of information already available for these very broad questions, in books and on the web. There's no point in somebody repeating it here. After you've done your research, if you have a more specific question, feel free to ask.

  • Collection classes for Forte

    Has anyone out there used a good set of collection classes for Fort&eacute;?
    I know about the Brahma Fortify product (very good, very expensive!) and I
    have heard of a product from Born, but I can't get hold of it yet.
    I'd love to hear from anyone who has
    a) used the Born collection classes
    or
    b) knows of other sets of collection classes
    many thanks,
    Tim Kimber
    EDS (UK)
    To unsubscribe, email '[email protected]' with
    'unsubscribe forte-users' as the body of the message.
    Searchable thread archive <URL:http://pinehurst.sageit.com/listarchive/>

    Hi,
    We had a similar requirement some time back and were
    evaluating what is available in the market. We then used Born's
    collection
    classes and found it quite useful. However, since our requirements
    were very specific, we developed our own set of collection classes.
    I feel Born's colleciton classes are a good place to start. Even if you
    want to buy an out-of-the-shelf suite, it will give you an idea of what
    you can expect and what you cannot.
    Born's classes are FREE and provide an interface-based library of useful
    collection classes, including sorted arrays, linked lists, binary trees,
    iterators and filters.
    You can get the collection classes by sending an email message to
    [email protected] with a subject line of "Born Collections"
    and the message "Send Born Collections" in the body of the message. The
    software and documentation will be sent back to you.
    Hope this helps!
    Ajith Kallambella M.
    Forte Systems Engineer,
    Internationational Business Corporation.
    From: General[SMTP:[email protected]]
    Reply To: General
    Sent: Monday, June 08, 1998 12:21 PM
    To: [email protected]
    Subject: Collection classes for Forte
    Has anyone out there used a good set of collection classes for Fort&eacute;?
    I know about the Brahma Fortify product (very good, very expensive!)
    and I
    have heard of a product from Born, but I can't get hold of it yet.
    I'd love to hear from anyone who has
    a) used the Born collection classes
    or
    b) knows of other sets of collection classes
    many thanks,
    Tim Kimber
    EDS (UK)
    To unsubscribe, email '[email protected]' with
    'unsubscribe forte-users' as the body of the message.
    Searchable thread archive
    <URL:http://pinehurst.sageit.com/listarchive/>
    To unsubscribe, email '[email protected]' with
    'unsubscribe forte-users' as the body of the message.
    Searchable thread archive <URL:http://pinehurst.sageit.com/listarchive/>

  • Help needed with collection classes

    Howdie all,
    I'm new to Java, and for the most part, I can do it.
    I'm stuck on how to do the following:
    I have to write a program that simulates a deck of cards, including shuffling (involving cards are re-collected), dealing cards. I have to create 52 objects of the card class. The only things that I can use involve some of the collection classes (arrays, dynamic lists, vectors, dictionaries), queues/stacks
    I dont know:
    ** what to use. should i use a dyn list or a vector
    **how the heck would i shuffle the cards?
    ** for dealing the cards, i figued i would just use a loop to draw a set of cards (face and suit)
    i am not asking for code on how to do it (though pseudo-code/alogorithm may help). i just dont know where to start..i am totally stuck.
    thanks a bunch!

    I would suggest you to use the LinkedList class for the deck representation.
    To create the cards you could use
    for i = 0 to 51
    new Card(i);
    In Card constructor do something like
    int colour = i/13+1; // (1-4, one for each colour)
    int value = i%13+1; // (1-13, ace-king)
    To shuffle you could
    for i = 0 to 100
    j = radom(52)
    k = random(52)
    swap(card#j, card#k)
    This will swap 2 random cards 100 times.
    To draw cards
    Card c = cards.remove(0)
    or
    Card c = cards.remove(radom(cards.size()))
    In the later, the shuffle part is not really needed.
    thought about this some more and now i have another
    question:
    when using a dyn linked library, i am not even sure
    how to create the 52 objects. previously when doing
    project like this, i just used a random function to
    generate the cards, and used switch statements for the
    non-numbered cards and for the suite. how would i do
    accomplish this when using a collection class?
    Howdie all,
    I'm new to Java, and for the most part, I can do it.
    I'm stuck on how to do the following:
    I have to write a program that simulates a deck of
    cards, including shuffling (involving cards are
    re-collected), dealing cards. I have to create 52
    objects of the card class. The only things that Ican
    use involve some of the collection classes (arrays,
    dynamic lists, vectors, dictionaries),queues/stacks
    I dont know:
    ** what to use. should i use a dyn list or avector
    **how the heck would i shuffle the cards?
    ** for dealing the cards, i figued i would just usea
    loop to draw a set of cards (face and suit)
    i am not asking for code on how to do it (though
    pseudo-code/alogorithm may help). i just dont know
    where to start..i am totally stuck.
    thanks a bunch!

  • Find best collection class for the scenarios given

    Hi Everyone,
    Can u help me in answering this questions:
    Indicate the most efficient / appropriate standard Java (JDK 1.4 or lower) collections class for each requirement. Do not use any classes that are not in the standard JDK (e.g. Apache commons-collections classes).
    2.1. An un-ordered, unique collection
    2.2. An insertion-ordered, non-unique collection
    2.3. A sorted, unique collection
    2.4. An insertion-ordered, unique collection
    2.5. Random access to elements within a list
    2.6. Insertion into random points within a list
    2.7. A last-in-first-out queue
    Please let me know what u think ?
    IF possible please tell me the reason why u selected one over the other
    Thanks in advance....

    2.1. An un-ordered, unique collection
    HashSet thereadOkay, why?
    2.2. An insertion-ordered, non-unique collection
    LinkedList thereadOkay, why?
    2.3. A sorted, unique collection
    TreeSet theread
    TreeMap kv pair thereadOkay, but is collection with a small "c" or Collection with a captial "C"? Maps don't implement the Collection interface. In a general sense, you could consider them collections, but in Java land, usually that implies single-valued groupings--i.e., those that implement Collection.
    >
    2.4. An insertion-ordered, unique collection
    LinkedHashSet theread
    LinkedHashMap thereadSame comments as above.
    2.5. Random access to elements within a list
    LinkedList (In fact any class that implements List
    Interface)No. Hint: Do you know what "random access" means, and why LinkedList is not a good choice?
    2.6. Insertion into random points within a list
    LinkedHashSet
    LinkedHashMapNo. It doesn't say anything about uniqueness or k/v pairs.
    2.7. A last-in-first-out queue
    StackOkay.
    2.8. List any of these classes which are not
    thread-safe, if any. How
    would you make these Collections thread-safe?
    HashSet, LinkedList, TreeSet, TreeMap, LinkedHashSet,
    LinkedHashMapI'm not going to match 'em all up one by one, but it seems about right.
    This is typically accomplished by synchronizing on
    some object that naturally encapsulates the collection
    class. If no such object exists, the map should be
    "wrapped" using the Collections.synchronizedMap
    method. This is best done at creation time, to prevent
    accidental unsynchronized access to the map:
    Map m = Collections.synchronizedMap(new TreeMap(...));Sounds about right. Also sounds like it was copied and pasted. If so, do you understand it?

  • Are Collection classes synchronized.

    I learned from the ver 1.2, which was the first to add collections framework that the collection classes were not synchronized and as such a programmer had to do it manually.
    What about in 1.4 and 1.5? Plz guide me.
    or
    plz give me some docs/links of help.

    There is a Collection class, which is the base class for all collections (such as List, Set, Map). Then there is a Collections class...which is like a Collection utility class...actually, i thin that's exactly what it is. If so, they should have called it CollectionUtil...when i first saw this class..it was confusng at first...then i noticed the "s" in Collection
    THe "Collections" class provides method to synchronize your "collection"
        List list = new ArrayList();   // unsynchronize list
        list = Collections.synchronizedList(list);  the 2nd line basically, say...use the collection utility class to create a wrapper around the list objject and make the list synchronized....return the wrapper 9wich is a synchronized list)
    to iterate over the collection
    synchronized(list) {
          Iterator i = list.iterator(); // Must be in the synchronized block
          while (i.hasNext())
             foo(i.next());
    }example taken from the Sun Java Collections API

  • To ragnic and other about Singleton class

    Hi ragnic. Thanks for your reply. I posted the code wrong. Heres' my correct one.
    I have a GUI first loaded information and the information is stored in a databse, I have some EJB classes..and my singleton class ABC has some method to access to the EJB..
    so my first GUI will gather info using singleton class and later if I click on
    a button in my first GUI class, will pop up another frame of another class , this class also need to class setPassword in my Singleton..
    are my followign codes correctly??
    iS my Class ABC a SINgleton class? thanks
    Is my class ABC use as single correctly. And It is called from other classes is also correct?
    I'm new to java and like to learn about Singleton class.
    But I really dont' understand it clearly after reading many examples of it.
    I have a project to convert my class abc to a singleton.
    But I dont know how to do it.
    In my class(soon will become a singleton) will have few methods that later I need to use it from another class A and class B.
    I have a GUI application that first load my class A..and my class will call
    class abc(singleton) to get some information from it.
    and then in class A has a button, if I click on that button I will call SIngleton class again to update my password, in the singleton class has method calls updatePassword. But I dont know how to call a singleton from other class.
    I have my code for them below:
    1)public class ABC //attempt using a singleton
    private static ABC theABC = null;
    private ABC(){}
    public synchronized static ABC getABC()
    if(theABC == null)
    theABC= new ABC();
    return the ABC;
    public void updateUserInfo(SimpleUser user)
    throws UserNotFoundException, DelegateException
    try
    UserCollectionHome userCollectionHome = (UserCollectionHome)
    EJBHomeFactory.getFactory().lookupHome("vista/UserCollection",
    UserCollectionHome.class);
    UserHome userHome = (UserHome)
    EJBHomeFactory.getFactory().lookupHome("vista/User",UserHome.class);
    UserCollection uc = userCollectionHome.create();
    uc.updateUserInfo(user, userHome);
    } catch(HomeFactoryException hfe) {
    hfe.printStackTrace();
    throw new DelegateException(hfe);
    } catch(RemoteException re) {
    re.printStackTrace();
    throw new DelegateException(re);
    } catch(CreateException ce) {
    ce.printStackTrace();
    throw new DelegateException(ce);
    } catch(FinderException fe) {
    fe.printStackTrace();
    throw new UserNotFoundException();
    public SimpleUser getID(String id)
    throws UserNotFoundException, DelegateException
    try
    UserCollectionHome userCollectionHome = (UserCollectionHome)
    EJBHomeFactory.getFactory().lookupHome("vista/UserCollection",
    UserCollectionHome.class);
    UserHome userHome = (UserHome)
    EJBHomeFactory.getFactory().lookupHome("vista/User",UserHome.class);
    UserCollection uc = userCollectionHome.create();
    SimpleUser su = uc.getID(id, userHome);
    return su;
    } catch(HomeFactoryException hfe) {
    throw new DelegateException(hfe);
    } catch(RemoteException re) {
    throw new DelegateException(re);
    } catch(CreateException ce) {
    throw new DelegateException(ce);
    } catch(FinderException fe) {
    throw new UserNotFoundException();
    public void setPassword(String lname,String pw)
    throws UserNotFoundException, DelegateException
    try
    UserCollectionHome userCollectionHome = (UserCollectionHome)
    EJBHomeFactory.getFactory().lookupHome("vista/UserCollection",
    UserCollectionHome.class);
    UserHome userHome = (UserHome)
    EJBHomeFactory.getFactory().lookupHome("vista/User",UserHome.class);
    UserCollection uc = userCollectionHome.create();
    uc.setPassword(lname,pw, userHome);//assume that all lname are differents.
    } catch(HomeFactoryException hfe) {
    hfe.printStackTrace();
    throw new DelegateException(hfe);
    } catch(RemoteException re) {
    re.printStackTrace();
    throw new DelegateException(re);
    } catch(CreateException ce) {
    ce.printStackTrace();
    throw new DelegateException(ce);
    } catch(FinderException fe) {
    fe.printStackTrace();
    throw new UserNotFoundException();
    }//Do I have my class as a Singleton correctly???
    2)//Here is my First Frame that will call a Singleton to gather user information
    public A(Frame owner)
    super(owner, "User Personal Information",true);
    initScreen();
    loadPersonalInfo();
    * This method instantiates all the GUI widgets and places them into panels and
    * onto the frame.
    private void initScreen()
    txtFname = new JTextField(20);
    txtLname=new JTextField(20);
    btnsave =new JButton("Save");
    btnChange= new JButton("Click here to change PW");//when you click this button there will be a frame pop up for you to enter informaton..this iwll call class B
    JPanel pnlMain=new JPanel();
    JPanel pnlFname= new JPanel();
    pnlFname.setLayout(new BoxLayout(pnlFname, BoxLayout.X_AXIS));
    pnlFname.setBorder(BorderFactory.createEmptyBorder(0,87,0,90));
    pnlFname.add(new JLabel("First Name:"));
    pnlFname.add(Box.createRigidArea(new Dimension(5,0)));
    pnlFname.add(txtFname);
    JPanel pnlLname= new JPanel();
    pnlLname.setLayout(new BoxLayout(pnlLname, BoxLayout.X_AXIS));
    pnlLname.setBorder(BorderFactory.createEmptyBorder(0,87,0,90));
    pnlLname.add(new JLabel("Last Name:"));
    pnlLname.add(Box.createRigidArea(new Dimension(5,0)));
    pnlLname.add(txtLname);
    pnlMain.add(pnlFname);
    pnlMain.add(pnlLname);
    pnlMain.add(btnsave);
    pnlMain.add(btnChange");
    btnSave = new JButton("Save");
    btnSave.setActionCommand("SAVE");
    btnSave.addActionListener(this);
    btnCancel = new JButton("Cancel");
    btnCancel.setActionCommand("CANCEL");
    btnCancel.addActionListener(this);
    JPanel pnlBottom = new JPanel();
    pnlBottom.setLayout(new BoxLayout(pnlBottom, BoxLayout.X_AXIS));
    pnlBottom.setBorder(BorderFactory.createEmptyBorder(25,55,0,0));
    pnlBottom.add(btnSave);
    pnlBottom.add(Box.createRigidArea(new Dimension(25,0)));
    pnlBottom.add(btnCancel);
    pnlMain.add(pnlBottom);
    this.setContentPane( pnlMain);
    setSize(500,500);
    GraphicUtilities.center(this);
    theABC=ABC.getABC();
    //Do I call my ABC singleton class correctly??
    private void loadPersonalInfo()
    String ID= System.getProperty("user.name");
    SimpleUser user = null;
    try {
    user = ABC.getID(ID);
    //I tried to use method in ABC singleton class. IS this correctly call?
    } catch(UserNotFoundException nfe)
    JOptionPane.showMessageDialog(new JDialog(),"You have not yet registered.",
    "User Not Found",JOptionPane.WARNING_MESSAGE);
    System.exit(0);
    } catch(DelegateException de) {
    JOptionPane.showMessageDialog(new JDialog(),"You have not yet registered",JOptionPane.ERROR_MESSAGE);
    System.exit(0);
    currentUser = user;
    txtFname.setText(currentUser.getFirstName());
    txtLname.setText(currentUser.getLastName());
    //This information will be display in my textfields Fname and Lname
    //I can change my first and last name and hit button SAVE to save
    public void actionPerformed(ActionEvent e)
    if(e.getActionCommand().equals("SAVE")) submitChanges();
    if(e.getActionCommand().equals("CHANGE_PASSWORD")) {
    changepassword=new ChangePassword(new Frame(),name,badgeid);
    public void submitChanges(){
    String currentNTUsername = System.getProperty("user.name");
    SimpleUser user =null;
    try {
    user = theABC.getID(ID);
    user.setFirstName(txtFname.getText().trim());
    user.setLastName(txtLname.getText().trim());
    currentUser = user;
    theABC.updateUserInfo(currentUser);
    //IS this correctly if I want to use this method in singleton class ABC??
    } catch(UserNotFoundException nfe)
    JOptionPane.showMessageDialog(new JDialog(),"You have not yet registered",
    "User Not Found",JOptionPane.WARNING_MESSAGE);
    } catch(DelegateException de) {
    JOptionPane.showMessageDialog(new JDialog(),"You have not yet registered",JOptionPane.ERROR_MESSAGE);
    System.exit(0);
    this.setVisible(false);
    3) click on ChangePassword in my above GUI class A..will call this class B..and in this class B
    I need to access method in a Singleton class- ABC class,,DO i need to inititates it agian, if not what should I do? thanks
    package com.lockheed.vista.userinfo;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;
    import javax.swing.border.*;
    import javax.swing.table.*;
    import javax.swing.tree.*;
    import java.util.StringTokenizer;
    import java.util.Vector;
    import java.io.*;
    import javax.swing.text.*;
    import javax.swing.text.html.*;
    import javax.swing.colorchooser.*;
    import javax.swing.filechooser.*;
    import javax.accessibility.*;
    import java.beans.*;
    import java.applet.*;
    import java.net.*;
    import org.apache.log4j.*;
    import com.lockheed.common.gui.GraphicUtilities;
    import javax.swing.*;
    import javax.swing.event.*;
    import javax.swing.border.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    import vista.user.UserServicesDelegate;
    import vista.user.SimpleUser;
    import vista.user.UserNotFoundException;
    import vista.user.*;
    import com.lockheed.common.ejb.*;
    import com.lockheed.common.gui.*;
    import com.lockheed.vista.publish.*;
    * This program allow users to change their Vista Web Center's password
    public class ChangePassword extends JDialog
    implements ActionListener{
    protected final Logger log = Logger.getLogger(getClass().getName());
    private UserServicesDelegate userServicesDelegate;
    private User currentUser = null;
    private JPasswordField txtPasswd, txtVerifyPW;
    private JButton btnSubmit,btnCancel;
    private JLabel lblName,lblBadgeID;
    private String strBadgeID="";
    * This is the constructor. It creates an instance of the ChangePassword
    * and calls the method to create and build the GUI.
    public ChangePassword(Frame owner,String name,String badgeid)
    super(owner, "Change Password",true);
    initScreen(name,badgeid);//build the GUI
    * This method instantiates all the GUI widgets and places them into panels and
    * onto the frame.
    private void initScreen(String strname,String strBadgeid)
    txtPasswd = new JPasswordField(20);
    txtVerifyPW=new JPasswordField(20);
    txtPasswd.setEchoChar('*');
    txtVerifyPW.setEchoChar('*');
    JPanel pnlMain=new JPanel();
    pnlMain.setLayout(new BoxLayout(pnlMain, BoxLayout.Y_AXIS));
    pnlMain.setBorder(BorderFactory.createEmptyBorder(20,0,20,0));
    JPanel pnlPW=new JPanel();
    pnlPW.setLayout(new BoxLayout(pnlPW, BoxLayout.X_AXIS));
    pnlPW.setBorder(BorderFactory.createEmptyBorder(0,96,0,30));
    pnlPW.add(new JLabel("Password:"));
    pnlPW.add(Box.createRigidArea(new Dimension(5,0)));
    pnlPW.add(txtPasswd);
    JPanel pnlVerifyPW=new JPanel();
    pnlVerifyPW.setLayout(new BoxLayout(pnlVerifyPW, BoxLayout.X_AXIS));
    pnlVerifyPW.setBorder(BorderFactory.createEmptyBorder(0,63,0,30));
    pnlVerifyPW.add(new JLabel("Verify Password:"));
    pnlVerifyPW.add(Box.createRigidArea(new Dimension(5,0)));
    pnlVerifyPW.add(txtVerifyPW);
    JPanel pnlTop= new JPanel();
    pnlTop.add(pnlPW);
    pnlTop.add(Box.createRigidArea(new Dimension(0,10)));
    pnlTop.add(pnlVerifyPW);
    pnlMain.add(pnlTop);
    btnSubmit = new JButton("Submit");
    btnSubmit.setActionCommand("SUBMIT");
    btnSubmit.addActionListener(this);
    btnCancel = new JButton("Cancel");
    btnCancel.setActionCommand("CANCEL");
    btnCancel.addActionListener(this);
    JPanel pnlBottom = new JPanel();
    pnlBottom.setLayout(new BoxLayout(pnlBottom, BoxLayout.X_AXIS));
    pnlBottom.setBorder(BorderFactory.createEmptyBorder(25,55,20,30));
    pnlBottom.add(btnSubmit);
    pnlBottom.add(Box.createRigidArea(new Dimension(25,0)));
    pnlBottom.add(btnCancel);
    pnlMain.add(pnlBottom);
    this.setContentPane( pnlMain);
    setSize(350,230);
    setVisible(true);
    public void actionPerformed(ActionEvent e)
    if(e.getActionCommand().equals("CANCEL")) this.setVisible(false);
    if(e.getActionCommand().equals("SUBMIT")) submitPW();
    * This method is called when the submit button is clicked. It allows user to change
    * their password.
    public void submitPW(){
    myABC= ABC.getABC();//Is this correct?
    char[] pw =txtPasswd.getPassword();
    String strPasswd="";
    for(int i=0;i<pw.length;i++){
    strPasswd=strPasswd+pw;
    char[] vpw =txtVerifyPW.getPassword();
    String strVerifyPW="";
    for(int i=0;i<vpw.length;i++){
    strVerifyPW=strVerifyPW+pw;
    if((strPasswd==null)||(strPasswd.length()==0)) {
    JOptionPane.showMessageDialog(new JDialog(),"You have not enter a password. Please try again.",
    "Invalid Password",JOptionPane.ERROR_MESSAGE);
    if((!strPasswd.equals(strVerifyPW)))
    //password and verify password do not match.
    JOptionPane.showMessageDialog(new JDialog(),"Your passwords do not match. Reenter and try again.",
    "Invalid Password",JOptionPane.ERROR_MESSAGE);
    try
    myABC.setUserPassword(strPasswd);//try to use a method in Singleton class
    txtPasswd.setText("");
    txtVerifyPW.setText("");
    this.setVisible(false);
    } catch(DelegateException e) {
    JOptionPane.showMessageDialog(new Frame(),
    "Error.",
    "Unable to change password information.",JOptionPane.WARNING_MESSAGE);
    } catch(UserNotFoundException e) {
    JOptionPane.showMessageDialog(new Frame(),
    "Error.",
    "Unable to change password information.",JOptionPane.WARNING_MESSAGE);
    And ofcourse I have other EJB classes to work with these classes.
    ***It compiles okey but when I ran, it say "NullPointerException"
    I think I call my Singleton wrong.
    Please help me.thanks

    1. When replying, use <reply>, don't post a new topic.
    2. Implementing a singleton is a frequently asked question. Search before you post.
    3. This is not a question about Swing. A more appropriate forum would be "New To Java Technology" or perhaps "Java Programming", but see point 1.
    4. When posting code, keep it short. It increases the chance of readers looking at it. And in composing your shorter version for the forum, you just may solve your problem.

  • About Collection and ForAll

    Dear Guru
    1) I have some documents about collection of 10g
    and example of Forall function.
    2) Question: I have procedure called Test_ps
    How to see the source code of the procedure
    A : User_source
    But i want to see how my parameter are there in procedure is there any option ?
    Advance Thanks..

    you can use DSEC <Procedure_Name> to see the list of arguments
    PRAZY@11gR1> create or replace procedure test_proc(a number,b number) is
      2  begin
      3  null;
      4  end;
      5  /
    Procedure created.
    Elapsed: 00:00:00.01
    PRAZY@11gR1> select text from user_source where name='TEST_PROC' order by line;
    TEXT
    procedure test_proc(a number,b number) is
    begin
    null;
    end;
    Elapsed: 00:00:00.01
    PRAZY@11gR1> desc test_proc;
    PROCEDURE test_proc
    Argument Name                  Type                    In/Out Default?
    A                              NUMBER                  IN
    B                              NUMBER                  INRegards,
    Prazy

  • Need help about Vector class in java

    Hello,
    I have some questions about Vector class. Please see this short code:
    Vector v = new Vector();
    v.add(New Integer(5));
    Is this the only way to add int value into vector? Performance wise, is this slow? And are there any better and faster way to add/get int element fro vector?
    Thank you very much in advance.

    Normally (up to Java version 1.4), that's the only way you can add an int to a Vector. The thing is that Vector can only contain Objects, and an int is a primitive, not an object. So you have to wrap the int in an Integer object.
    However, Java 5 has a new feature, called autoboxing, which means that the compiler automatically wraps primitive values into objects, so that you can program it like this:
    Vector v = new Vector();
    v.add(5);Note, this will not make your program faster or more efficient, because the compiler translates this automatically to:
    Vector v = new Vector();
    v.add(new Integer(5));So in the end, the same bytecode will be produced. Autoboxing is just a feature to make life more convenient for the programmer.

  • Confusion... Data Access Object and Collection Class

    Please help me...
    i have a Book class in the library system, so normally i would have a Collection class eg. BookCollection class which keeps an array/ arrayList of Book objects. In BookCollection class i have methods like
    "searchBook(BookID)" which would return me a Book object in the array.
    But now i'm confused with Data Access Object... In sequence diagrams there's a "Data Access class" which is used to retrieve data from and send data to a database. So, if i have the Data Access class, do i still need BookCollection class? Because BookCollection serves as a database also rite? ...

    I think you're in the right rail.
    The BookCollection class could be still usefull if you will need to manage search results with more than onne record (e.g.: search by author name).

  • Question about abstract classes and instances

    I have just read about abstract classes and have learned that they cannot be instantiated.
    I am doing some exercises and have done a class named "Person" and an abstract class named "Animal".
    I want to create a method in "Person" that makes it possible to set more animals to Person objects.
    So I wrote this method in class Person and compiled it and did not get any errors, but will this work later when I run the main-method?
    public void addAnimal(Animal newAnimal)
         animal.add(newAnimal);
    }Is newAnimal not an instance?

    Roxxor wrote:
    Ok, but why is it necessary with constructors in abstract classes if we don�t use them (because what I have understand, constructors are used to create objects)?Constructors don't create objects. The new operator creates objects. An object's c'tor is invoked after the object has already been created. The c'tors job is to initialize the newly-created object to a valid state. Whenever a child object is created, the parent's c'tor is run before the child's c'tor, so that by the time we're inside the child's c'tor, setting up the child's state, we know that the parent (or rather the "parent part" of the object we're initializing) is in a valid state.
    Constructor rules:
    1) Every class has at least one ctor.
    1.1) If you do not define an explicit constructor for your class, the compiler provides a implicit constructor that takes no args and simply calls super().
    1.2) If you do define one or more explicit constructors, regardless of whether they take args, then the compiler no longer provides the implicit no-arg ctor. In this case, you must explicitly define a public MyClass() {...} if you want one.
    1.3) Constructors are not inherited.
    2) The first statement in the body of any ctor is either a call to a superclass ctor super(...) or a call to another ctor of this class this(...) 2.1) If you do not explicitly put a call to super(...) or this(...) as the first statement in a ctor that you define, then the compiler implicitly inserts a call to super's no-arg ctor super() as the first call. The implicitly called ctor is always super's no-arg ctor, regardless of whether the currently running ctor takes args.
    2.2) There is always exactly one call to either super(...) or this(...) in each constructor, and it is always the first call. You can't put in more than one, and if you put one in, the compiler's implicitly provided one is removed.

  • Collection Class

    I have import two classes class1, class2 in a Class3 program. Class1 contains get and set methods. Class2 and Class3 coding is as follows. In Class2, I have passed the Class1 object. Now my problem is when I try to get the values in Class3 through get method of class1 using Collection class, I get only null values. Kindly tell me how to correct my problem.
    class c2
             public Collection selecting(Class1 c1) throws Exception
                        ResultSet rs = null;
                        PreparedStatement ps = null;
                        Connection con = null;
                        Collection result = new ArrayList();
                        con = getConnection();
                        id =  c1.getId();
                        String sql = "select * from table1 where id=?";
                        ps = con.prepareStatement(sql);
                        ps.setInt(1,id.intValue());
                        rs = ps.executeQuery();
                        while(rs.next())
                                   c1.setName("Name"));
                                   c1.setDesc("Desc"));
                                   result.add(c1);
    }     class c3
             public static void main(String[] arg)
                     e=Integer.valueOf(request.getParameter("id"));
                     c1.setCategoryId(e);
                     Collection sel = c2.selecting(c1);
                     Iterator i = sel.iterator();
                     while(i.hasNext())
                             s=c1.getName();
                             f=c1.getDesc();
                             out.println("<b> "+s+","+f+"<br>");
    }

    Don't Mistake me. I have send only a part of program. I have used return statement in my program. I need solution for ,how to get the values from Collection class object when a class object is passed as argument.
    Collection sel = c2.selecting(c1);Here c1 is object of class1 which contains methods like
    getName(),
    getDesc(),
    setName(),
    setDesc();

  • A question about Object Class

    I got a question about Object class in AS3 recently.
    I typed some testing codes as following:
    var cls:Class = Object;
    var cst:* = Object.prototype.constructor;
    trace( cls === cst); // true
    so cls & cst are the same thing ( the Object ).
    var obj:Object = new Object();
    var cst2:* = obj.constructor.constructor;
    var cst3:* = obj.constructor.constructor.c.constructor;
    var cst5:* = Object.prototype.constructoronstructor;
    var cst4:* = Object.prototype.constructor.constructor.constructor;
    var cst6:* = cls.constructor;
    trace(cst2 === cst3 && cst3 === cst4 && cst4 === cst5 && cst5 === cst6); //true
    trace( cst == cst2) // false
    I debugged into these codes and found that cst & cst2 had the same content but not the same object,
    so why cst & cst2 don't point to the same object?
    Also, I can create an object by
    " var obj:Object = new cst();"
    but
    " var obj:Object = new cst2();"
    throws an exception said that cst2 is not a constructor.
    Anyone can help? many thanks!

    I used "describeType" and found that "cst2" is actually "Class" class.
    So,
    trace(cst2 === Class); // true
    That's what I want to know, Thank you.

  • Collection classes, count

    I am attempting to count occurances of a string being added in a collection class. This is what I have
    class CountOccurrencesListener implements ActionListener
    public void actionPerformed(ActionEvent event)
    String target = targetText.getText( );
    feedback.append(target + " occurs ");
    int answer = countOccurrences(answer);
    feedback.append(answer + " times.\n");
    public int countOccurrences(String target, int answer)
    int index;
    answer = 0;
    for (index = 0; index < manyItems; index++)
    if (target == data[index])
    answer++;
    return answer;
    It should count how many times a string was added from the text field, TargetText, but I get this error message:
    "BagApplet.java": Error #: 300 : method countOccurrences(int) not found
    any ideas on what I am doing wrong

    To cure that error, change "int answer = countOccurrences(answer)" to:
    int answer = countOccurrences(target,answer);
    You either left out some code in your post or you will find additional errors.

  • Book excerpt about Collections

    http://java.sun.com/developer/Books/javaprogramming/javaobjects/ch06final.pdf
    Nowhere in this free chapter does the author advise to declare Collections by specifying the least specialized type possible
    it's always something like :
    ArrayList arrayList = new ArrayList();
    // using Collection methods only, like "add()"...By doing so, aren't we losing one of the most interesting aspect of Collections : designing by contract and being able to swap implementations as the needs change ?
    Do you think this is irrelevant in a chapter about collections but belongs to a pure OO chapter ?
    Just wondering...

    I've only skipped the chapter, so I might miss anything. But I'll give you my two Euro-Cents nevertheless:
    - I think it should be mentioned in the chapter, even 'though that chapter obviously is not about that specific concept. More importantly the chapter should really use that paradigm throughout it's example code. I think in this case giving correct examples is much better than repeating the message again and again.
    - The chapter does mention using a simple wrapper about the list to hide away the use of the concrete list implementation in favour of a more business-orientet interface (Transcript+TranscriptEntry vs. ArrayList<TranscriptEntry>). IMO that is another approach to the same "problem".

Maybe you are looking for

  • Static NAT (in and out) and PAT on a Router

    Static NAT and PAT I need to have a customer network connected to my extranet. I’m not in control of the customer network addressing. But need to configure a VPN connection. I will supply the router that will also be the customer Firewall to the Inte

  • Adobe CS6 Extended Student Teacher Edition registration Q:

    Hi I am going to buy Adobe CS6 Extended Student Teacher Edition when I start with an online colledge comming up and I want to know if I will be elegable for this edition. I read the requirements and it did not cover online colleges. Thanks for any he

  • Invalid digital signature

    Hi, I developing software in Delphi 7 which digitaly sign pdf documents. But I have a problem and can't solve it for few days. 1) I make simply pdf document just for test purposes. 2) Then I create required objects (Signature Fields, Signature Value

  • SAP Table in COPA

    Hello All, I am facing the problem in COPA customisation, I have to create the characteristic for billing document line item through table VBRP but when i select transfer from SAP table to create then the table is not available in that Table List . h

  • The light on the start button flashes on and off.

    Hi My Power Mac will not boot up.However the light on the start button flahes on and off. At first I thought the disc was dead-but now I am not so sure... Any suggestions anyone? What does the flashing light mean? thanks