Iterating/indexOf Question

The user is trying to guess the computers word one letter at a time. I kind of figured it out using the indexOf method, but it doesn't work if the same letter is in the word more than once. If the user gets the letter right, I'm trying to have the computer say where the letter is located.
I.e. if the secret word is "believe" and the user guesses "e", I want computer to say that there is an e in the 2nd, 5th, and 7th blanks.
Any tips?
Here is the very cumbersome thing I put together:
                indexHolder = itsComputersWord.indexOf(itsUsersLetter);
                if (indexHolder == 0)
                    JOptionPane.showMessageDialog (null, "The letter you guessed is the first letter of the secret word.");
                if (indexHolder == 1)
                    JOptionPane.showMessageDialog (null, "The letter you guessed is the second letter of the secret word.");
                if (indexHolder == 2)
                    JOptionPane.showMessageDialog (null, "The letter you guessed is the third letter of the secret word.");
                if (indexHolder == 3)
                    JOptionPane.showMessageDialog (null, "The letter you guessed is the fourth letter of the secret word.");               
                if (indexHolder == 4)
                    JOptionPane.showMessageDialog (null, "The letter you guessed is the fifth letter of the secret word.");

Why don't you do it la Hangman? :D (I love that game)
String word = "believe";
StringBuffer userAttempts = new StringBuffer();
for (int i = 0; i < word.length(); i++) {
  userAttempts.append(word.charAt(i) == ' ' ? ' ' : word.charAt(i)); // multiple words: leave spaces intact
while (!userAttempts.toString().equals(word)) {
  //: get letter from the user, into "attempt" (char)
  for (int i = 0; i < word.length(); i++) {
    if (word.charAt(i) == attempt)
      userAttempts.setCharAt(i, attempt);
System.out.print("Word: " + userAttempts + ". Next guess? ");
}s
(hint: something in the code above, which iterates over the letters in the word, is what you're looking for even without such a Hangman-like game)

Similar Messages

  • Iterator Refresh Question

    Hello there,
    i have a case where i have a search screen that is based on a table , let's say employees, the results is an ADF Read Only table. I brought the department name from the deparments View object to the employees View object so i can see the name as well as the id in my Results. Now i have a button Create , when i create an employee and enter a department id and then press save , the page results to the search screen where the new record i created appears with the department id but without the department name.
    My primary thought was to set the refresh iterator property but i'm not being able to solve my problem.
    Anyone can help me ?

    In your backing bean, if you have access to the binding container, run something like the following:
    DCIteratorBinding iter = (DCIteratorBinding)bindings.get("MyIteratorName");
    iter.execute();You can gain access to the binding container by doing the following:
    1. Define an instance-level field in the backing bean:
    private BindingContainer bindings;2. Add a getter and setter for the field:
        public BindingContainer getBindings() {
            return bindings;
        public void setBindings(BindingContainer bindings) {
            this.bindings = bindings;
        }3. Add a managed-property to the definition of your backing bean in faces-config.xml:
      <managed-bean>
        <managed-bean-name>myBackingBean</managed-bean-name>
        <managed-bean-class>com.acme.backing.MyBackingBean</managed-bean-class>
        <managed-bean-scope>request</managed-bean-scope>
        <managed-property>
          <property-name>bindings</property-name>
          <value>#{bindings}</value>
        </managed-property>
      </managed-bean>If you don't want to add a managed property to the bean, you can locate the BindingContainer like this:
    FacesContext ctx = FacesContext.getCurrentInstance();
    Application app = ctx.getApplication();
    ValueBinding bind = app.createValueBinding("#{bindings}");
    BindingContainer bindings = (BindingContainer)bind.getValue(ctx);

  • InputText value is not getting updated in Iterator

    Hi All,
    We are using jdeveloper 11.1.1.5.
    I have having 2 bounded taskflows TF1 and TF2. In TF1 I am having Page1.jspx and in
    TF 2 I have Page2.jspx.
    I am having 1 page fragment Frag1.jsff inside that I am having 1 textbox and a button. Text box is binded to the iterator "iter1".
    In Page1.jspx I have added fragment as a region and also I have added the iterator "iter1" in the bindings of page1.jspx
    On page load I am getting the value in the text box after that I am updating the text
    box value and on click of button I am trying to get the text box value using
    following methods.
    (1) Finding the Iterator getting the row and then finding the value as
    Row.getAttribute("Name");
    DCIteratorBinding dciter = bindingsImpl.findIteratorBinding("IName of the Iterator");
    Row row = dciter.getRowAtRangeIndex(0);
    row.getAttribute("Name of the attribute);
    (2) Finding the RichSelectOneChoice component and then getting value
    RichSelectOneChoice textbox= jsfUtils.findComponentInRoot("ID of the component");
    textbox.getValue();
    (3) Using the page definition attribute as :-
    +jsfUtils.resolveExpression("#{data.PageDefName.inputtextname.inputValue}");+
    Every time I am getting null value. Is there anything I am missing here.
    When I applied autosubmit="true" property on the textbox I am getting value from the
    1st method.
    *Question 1 : - Is it necessary to use autosubmit property on the text box for the values to get updated in Iterator ?*
    *Question 2 : - Why I am not able to find the value using 2nd method ?*
    *Question 3 : - Is there anything wrong in getting value from page definition using 3rd method?*
    Now When on click on button on page1 on some condition, I am navigating it to page2
    and there is a button on page2 which invokes the TaskFlow return activity and so
    returning back to TF1.
    Now again I am clicking on the button on page1 but this time again I am getting value
    of the textbox as null using all the methods :(
    I have checked various post and tried putting *changeEvent="ppr"* in ur pageDef
    against the respective VO entry but still after returning back from TF2 to TF1 values
    are lost in the Iterator.
    I tried sharing data control with calling taskflow but still I am not getting the
    updated values.
    Please suggest.
    Thanks in advance.
    --NavinK

    Hi Suresh,
    I already have autoSubmit=true for input text and partialSubmit=true for button but still getting the same error.
    --Navin K                                                                                                                                                                                                                                                                                       

  • Row selection messed up after sorting

    JDev version: 11.1.1.4 (but also reproducable in 11.1.2.1)
    See http://kpdwiki.be/Bart_L/tableIteratorSortSync.zip (open BO726.jws and run runThis.jspx)
    Situation:
    - iterator 'EmployeesIterator' which points to a view with Employees -> ChangeEventPolicy='none'
    - Bindings which all point to this iterator:
    - Tree binding 'Employees' used for an af:table with employees (firstname, lastname)
    - Attribute bindings 'FirstName' and 'LastName' which is used in a formLayout to show the currently selected employee
    - Operation Bindings to iterate through the employees (First, Previous, Next, Last)
    - runThis.jspx
    - formlayout with FirstName and LastName
    -> partialtriggers: Next-button and table (for the rest, no partialtriggers)
    - Next-button
    - table with employees
    Problem:
    1) if you select one of the employees in the table, and sort one of the columns, the first row will be selected. This is normal behaviour
    2)
    a) select the first row
    b) press the 'Next' button a few times. Now the selected employee in the iterator is 'X'
    c) in the table, select employee 'X' by clicking on its row
    d) sort one of the columns.
    Result: In the iterator, the first row of the table is selected, while the table selection shows something different!
    --> this is different behavior than the situation described in 1)
    --> after doing something with the table (sorting, filtering, selecting rows, ...), I would expect that the selected row in the table is always the same as the selected row in the iterator.
    Questions:
    1) Is this a bug?
    2) If yes, is this a known bug?
    3) If no: am I doing something which is not allowed? Or should I do something different here?

    I can reproduce the problem in 11.1.1.4.
    First employee is Steven King, which is selected. I then press next a few times till the output text reads Bruce Ernst (the table selection is still on Steven King, while the iterator points to Bruce Ernst). I then click on Bruce Ernst in the table, so it is selected (iterator stays on the same record). If I then sort the table, the table selection stays on Bruce Ernst, while the output text shows the first record in the table after the sort.
    We have the same issue using a non-modal popup to edit table rows (non-isolated task flow, sharing data controls & transaction). Our edit popup has navigation controls. When we scroll through records in the popup, the table selection doesnt refresh (changeEventPolicy = none). If we then select the record in the table that we scrolled to in the popup , without closing the popup, and then sort the table (with the popup still open), the selection stays on the previously selected record, whille the popup shows the first record in the table after the sort.

  • Multiple function signatures in JSP custom tag file

    I'm writing a jsp .tag file and I've encountered the following problem. I have those two functions :
    private void iterateThroughChildElements(Element element)
         for (Iterator i = question.getElements().iterator(); i.hasNext(); )
              this.parseAndDisplay( (Element) i.next() );
    private void parseAndDisplay(Question question)
    private void parseAndDisplay(Answer question)
    (......)Both Answer and Question objects are elements but I get an error from the compiler which says that no correct signature was found for the parseAndDisplay function.
    What could be the problem ? Do I have to cast the objects according to a instanceof comparaison ??

    There was an error in my code, it is as follows :
    private void iterateThroughChildElements(Set elements)
         for (Iterator i = elements.iterator(); i.hasNext(); )
              this.parseAndDisplay( (Element) i.next() );
    }

  • Multiple function signatures in .tag file

    I'm writing a jsp .tag file and I've encountered the following problem. I have those two functions :
    private void iterateThroughChildElements(Element element)
         for (Iterator i = question.getElements().iterator(); i.hasNext(); )
              this.parseAndDisplay( (Element) i.next() );
    private void parseAndDisplay(Question question)
    private void parseAndDisplay(Answer question)
    (......)Both Answer and Question objects are elements but I get an error from the compiler which says that no correct signature was found for the parseAndDisplay function.
    What could be the problem ? Do I have to cast the objects according to a instanceof comparaison ??

    Both Answer and Question objects are elements but I
    get an error from the compiler which says that no
    correct signature was found for the parseAndDisplay
    function.The compiler is borking with the following line this.parseAndDisplay( (Element) i.next() ); You are telling it you are passing an (Element) but you have only implemented the specific function for (Question) and (Answer).
    What could be the problem ? Do I have to cast the
    objects according to a instanceof comparaison ??Use polymorphism and add the function
    private void parseAndDisplay((Element) element) {
    element.parseAndDisplay() ;
    }Then move the parse and display functionality from this class into the similar named functions in the Question and Answer classes.

  • Show/Hide nested subforms

    Hey all,
    Since I didn't get a response on the issue I had on post
    lisa j richards, "Save and Export Data format issue/question" #, 1 Aug 2006 8:30 am, I spent a couple days and completely recreated the form using inherent bindings which actually messes up usability of the form a bit, but what can you do?
    Anyway, since I think we'll have to go in and manually delete all the "infoOnly" type fields in the XML, I'd like to try to make it as easy as possible to find and delete that information which means limiting the subforms into one main subform (tag). One of the tags that needs to go under this subform needs the ability to show and hide. It was working before I redid the form by using setInstances() in it's own subform of the root. I now need to move it down a level.
    _subformMain.subformSub.setInstances(1); does not work.
    subformMain.subformSub.instanceManager(1); doesn't work, and
    xfa.pathTo.subformMain.subformSub...(1); doesn't work (I've tried several iterations)
    The question is this, how can I keep a parent subform visible and hide one of its child subforms by using a button (or in this case radio button fields) located in a different subform?
    Thanks!
    Lisa
    Lisa

    > Any ideas?
    Yes.
    Check the uberlink and MacFly tutorials at PVII -
    http://www.projectseven.com/
    and the Navbar tutorial/articles at Thierry's place
    http://tjkdesign.com/articles/dropdown/
    Or this one (more recent article):
    http://tjkdesign.com/articles/Pure_CSS_Dropdown_Menus.asp
    Or to get it done fast, go here -
    http://www.projectseven.com/tutorials/navigation/auto_hide/index.htm
    (Stop trying to recreate the wheel!)
    Murray --- ICQ 71997575
    Adobe Community Expert
    (If you *MUST* email me, don't LAUGH when you do so!)
    ==================
    http://www.projectseven.com/go
    - DW FAQs, Tutorials & Resources
    http://www.dwfaq.com - DW FAQs,
    Tutorials & Resources
    ==================
    "RSW14" <[email protected]> wrote in message
    news:gmp4kn$7qu$[email protected]..
    >I have a navigation div with a set of navigation links in
    a linked list,
    >and
    > one of the links has sub links in a nested linked list.
    I want the nested
    > links
    > to only appear when the parent link is clicked, and then
    to hide when the
    > parent is clicked again. I currently have the links and
    nested links in
    > place
    > but don't know how to get the nested links to show/hide.
    >
    > I've shown the basic layout in the attached code.
    >
    > Any ideas?
    >
    > I was surprised to find little or no information on the
    web about this. Am
    > I
    > missing something - is this bad web design to show/hide
    nested links in a
    > navigation div?
    >

  • Migrating Struts/ADF 10.1.2 = 10.1.3, model validation not called

    As said in thread
    reportErrors(PageLifecycleContext ctx) not called
    Old Struts 10.1.2 can remain as is and will work in JDev 10.1.3.
    For some unexplained reason in my new account registration action, the entity validation method doesn't get called after migration?
    This jsp and action are similar to the toyStore new account creation,
    10.1.3 trace extract:
    as you see prepareToCreateNewAccount
    06/07/08 20:20:38 com.photoswing.webview.actions.AccountRegisterAction.prepareModel webAccountAM call to prepareToCreateNewAccount
    06/07/08 20:20:38 com.photoswing.model.site.AccountInSiteImpl.create BEGIN
    06/07/08 20:20:38 com.photoswing.webview.actions.AccountRegisterAction.prepareModel END
    06/07/08 20:20:38 com.photoswing.webview.actions.AccountRegisterAction.processUpdateModel BEGIN
    06/07/08 20:20:38 com.photoswing.webview.actions.AccountRegisterAction.processUpdateModel actionForm: oracle.adf.controller.v2.struts.forms.BindingContainerActionForm
    06/07/08 20:20:38 com.photoswing.webview.actions.AccountRegisterAction.processUpdateModel curLogin:
    06/07/08 20:20:38 com.photoswing.webview.actions.AccountRegisterAction.validateModelUpdates BEGIN skipCycle: false
    06/07/08 20:20:38 com.photoswing.webview.actions.AccountRegisterAction.validateModelUpdates mystr: null
    06/07/08 20:20:38 com.photoswing.webview.actions.AccountRegisterAction.validateModelUpdates call to super.validateModelUpdates
    06/07/08 20:20:38 com.photoswing.webview.actions.AccountRegisterAction.validateModelUpdates after call to super.validateModelUpdates, this.hasErrors(ctx): false
    JDev 10.1.2 extract:
    06/07/08 20:41:45 com.photoswing.model.site.AccountInSiteImpl.create BEGIN
    06/07/08 20:41:45 com.photoswing.webview.actions.AccountRegisterAction.prepareModel END
    06/07/08 20:41:45 com.photoswing.webview.actions.AccountRegisterAction.processUpdateModel actionForm: oracle.adf.controller.struts.forms.BindingContainerActionForm
    06/07/08 20:41:45 com.photoswing.webview.actions.AccountRegisterAction.processUpdateModel curLogin:
    06/07/08 20:41:45 com.photoswing.webview.actions.AccountRegisterAction.validateModelUpdates BEGIN skipCycle: false
    06/07/08 20:41:45 com.photoswing.webview.actions.AccountRegisterAction.validateModelUpdates mystr: null
    06/07/08 20:41:45 com.photoswing.webview.actions.AccountRegisterAction.validateModelUpdates call to super.validateModelUpdates
    06/07/08 20:41:45 com.photoswing.model.site.AccountInSiteImpl.validateEntity BEGIN
    etc ...
    Thank you for giving me a clue.
    Fred

    I traced my program, the action form has all the pending values entered in the jsp page but the View Row isn't updated?
    extract of pending values:
    06/07/09 12:05:47 com.photoswing.webview.actions.AccountRegisterAction.processUpdateModel actionForm, key: Email, value: [email protected]
    06/07/09 12:05:47 com.photoswing.webview.actions.AccountRegisterAction.processUpdateModel actionForm, key: FirstNameLatin, value: aaaxxx
    For your info:
    Service update 4 was installed.
    The navigation event to the review page is not a commit action.
    My trace shows that:
    -my prepareToCreateNewAccount is called when the jsp is first accessed (no event handling)
    - after activating next button:
    - no new call to prepareToCreateNewAccount => ok
    - processUpdateModel is called
    - the ActionForm gets filled => ok
    - validateModelUpdates is called
    but VO row (based on one Entity) and Entity set and validation methods are not called?
    My page def has only one iterator?
    Question when and where does the framework copy ActionForm values to underlying VO?
    I noticed that there were new ActionForm classes:
    oracle.adf.controller.v2.struts.forms.BindingContainerActionForm
    Do they work with
    <set-property property="v1ActionClass"
    value="com.photoswing.webview.actions.AccountRegisterAction"/>
    I need a clue!
    I'm lost!
    Regards
    Fred

  • Effective variable declaration

    Here is an interesting question!
    I have this code snippet:
    for (Iterator it = collection.iterator(); it.hasNext();) {
                Object elem = (Object) it.next();
            }Declaring my variable within the for loop, seems to be correct, in terms of reducing the variable scope, right? What happens though with memory issues?
    Doesn't this mean that the amount of objects that will be created will be equal to the collection's size??
    And what about this?
        Object elem;
            for (Iterator it = collection.iterator(); it.hasNext();) {
                elem = (Object) it.next();
            }This means that only one obj will be created and its value will change during the iteration?
    Question: Which code block is more 'right' in terms of effectiveness??
    Thanks

    No. The objects already exist in the collection. Your variable elem is simply another reference to an object that already exists, it is not a new object, so declaring the variable inside of, or outside of, the loop has very little meaning as far as memory usage goes.
    Even if it did create a new Object (by using clone, maybe) there would still be no big memory hit from declaring it inside of the loop, as with each iteration the previous object goes out of scope and will be garbage collected. It could cause a problem if it contained large objects using that clone method and ran many thousands of times before the garbage collector could catch up, but this is a rare case.

  • Hierarchy of IS Banking

    Hi Expert,
    Can any one help me about IS-Banking hierarchy. what are the basic settings need  to configure for IS Banking.
    Thanks & Regards,
    Nagesh.

    Dear Nagesh,
    Sorry, the text editor does not really offer line breaks, so it might look awful.
    Can you give more clues which area of the IMG you are looking into exactly?
    As you are ware, IS Banking is offering a number of components, which have their own basic settings and recommended sequence of moving on.
    Let's be specific, are you looking into the IS Banking part
    + Transactional Banking on the banking services platform
    + Analytical Banking on the banking services platform
    + Bank Customer Accounts or the Risk and Limit Analyzer on ECC 6.0?
    Since SAP does not in general publish a full configuration guide, the best approach to acquiring an answer about
    the logical hierarchy of the IMG items to run sequentially in a recommended way, are
    + training (everybody loves this recommendation, right?)
    + working out an own version of a sample configuration guide along an IDES or other reference/self-study system
    + learn from colleagues and start asking questions (that's what we are doing here)
    As long as you do not look by chance into the following
    + the hierarchy of organizations/branches in the SAP Org Management
    (where the answer would be, take a deep dive into Org Management)
    but into the logical hierarchy of the IMG items to run sequentially in a recommended way
    then here is a quick guide which is in principle valid for both
    + Transactional Banking on the banking services platform
    and
    + Bank Customer Accounts on ECC 6.0
    Hope this helps a bit.
    If this does not answer your question, then please rephrase and try to be specific.
    regards
    Ralf
    1. Start with setting up the application scope before doing so for the bank's own procedures and customer procedures
    1.1 Activate all components, functions, BADI's, BTE's, country settings needed
    (e.g. for Deposits Management: PLM, PCO, MCM, CMS if needed plus their BTE's/BADI's plus partner components plus etc.)
    1.2 If appropriate, connect a Solution Manager instance with the application system for Business Process Modelling and a link to application configuration
    2. Continue with setting up the bank's own procedures before doing so for the customer procedures
    2.1 FI01, and a file feed to bank directory
    2.2 Org Management, the branch directory and source for workflow
    2.3 User Management/pfcg, Authorizations, Roles, Profiles
    2.4 The GL settings might come next
    2.5 The End-of-Day settings might come next
    2.6 Item Management might come next, with the settings for transaction types, statements, counters etc.
    2.7 Contract Management might come next in full
    2.8 Product Management might come next, with the Financial Conditions workbench, Limits first
    2.9 Then determine the product attribute hierarchy next, before
    2.10 Building up the product defaults and restricted values in the Product Configurator
    3. Cross-Application Procedures > SAP Business Partner
    and remaining configuration
    After that, keeping a specific sequence is no longer really essential.
    Before, as listed above, that sequence avoids a lot of iterations and questions or even locking in some configuration which would have done differently if known the impact before.
    Edited by: Ralf Fischer on May 27, 2010 6:34 PM

  • Yet another Try Catch question. Iterating through a ForEach loop

    Confused on error handling in a Powershell ForEach loop. I’m looping through a list of registry keys, attempting
     to open each one. If it succeeds, I do a bunch of stuff. If it fails, I want to skip to the next iteration.
    If I was doing It in VBScript I’d do this:
    For Each Thing In colThings
    Open Thing
    If Err.Number <> 0 Then
    “oops”
    Else
    Do stuff
    Do stuff
    Do stuff
    End If
    Next
    This is what I came up with in PowerShell. It seems to work, but just doesn’t seem powershell-ish. There must be a better way to use the catch output than just creating a $return variable and assigning it success or fail?
    ForEach ($subKeyName in $subKeyNames)
    try{$subKey = $baseKey.OpenSubKey("$subKeyName")}
    catch{$return = "error" }
    If($return -eq "error" )
    “Oops”
    Else
    Do stuff
    Do stuff
    Do Stuff

     
    I totally get what you're saying about formatting. I don't' have any habits yet, since I've only been working in Powershell since... well, what time is it now?
    Unfortunately, It Has Been Decreed that we are no longer to use VBScript for any engineering solutions at work, so my 15 years experience in it now needs to be transitioned over asap. I don't have the luxury of crawling before I run. I'm trying not to be
    frustrated, but it's like an English major waking up one day and being told "You must now speak French exclusively. Here's a book."
    The Do Stuff example of my ForEach loop is about 50 lines of code involving matching values in subkeys of this registry key with another and collecting output. I tried wrapping the whole thing in a try section based on some examples, but it seemed odd, that's
    why I'm asking. I'm used to tightly focused error handling at the point where an error may occur.
    In this example I'm only interested in whether or not I can open the subkey (it exists, but I may not have permission). If I can't, there's no point in continuing with this iteration of the loop, I want to skip to the next one. So why include all the "Do
    Stuff" in the the try section? From a readability viewpoint, it doesn't seem helpful.
    Also, there may be more error handling deeper in the code. If I then put that in a try/catch, and then something else inside that, now I have nested try/catches mixed in with nested if/elses, all wrapped in a For loop.
    Again, I can see how it works logically, but for readability not so much, and having all these braces 50 lines apart to match up is giving me eye strain :).
    It sounds like David is agreeing with jrv, that putting the entire ForEach loop code into a try/catch is the conventional way to do it. I guess it makes as much sense as putting it all in an If-else-Endif, and I just need to adjust my paradigm.
    But if not, my specific question was more along the lines of, is there a built in way to tell that the catch section has been executed, rather than me using it to populate an arbitrary variable and then read it? In VBScript, you execute something, and the
    next line, you check the Err.number. I wasn't sure if you could do that with a try/catch.

  • Help with a simple iterator question

    the question is how to reset an iterator so it points to the beginng of a collection. Here is a piece of code. Thanks in advance:
    import java.io.*;
    import java.util.*;
    public class IteratorTest {
    public static void main(String[] args) {
    List list = new ArrayList();
    for (int i=0; i<10; i++) {
    list.add(new Integer(i));
    Iterator it = list.iterator();
    while (it.hasNext()) {
    System.out.println(it.next());
    // want to reset iterator here without
    // it = list.iterator();
    while (it.hasNext()) {
    System.out.println(it.next());

    Instead of using an Iterator, use a ListIterator.
    ListIterator it = list.listIterator();
    // walk forwards
    while (it.hasNext()) {
      it.next();
    // walk backwards
    while (it.hasPrevious()) {
      it.previous();
    // walk forwards again
    while (it.hasNext()) {
      it.next();
    }

  • Iterator Interface.A question please.

    I am unable to grasp the meaning of the following below :
    As we all know,Interfaces have abstract methods,(ie methods that
    have no body) and any class that implements the Interface has to
    implement the methods defined in the interface.That is,write the body for those methods.
    So far so good.
    Now coming to Collections called Vector.
    We have the 'Iterator' interface implemented by the vector class.
    The Iterator interface has the methods hasNext(),next().
    and we have the following code in the our class which iterates thru'
    the vector:
    MyClass item;
    while(iter.hasNext())
    item = (MyClass)iter.next();
    // Do something here.....
    Now we are using the methods hasNext() and next() above.
    But as they belong to the Iterator interface,(which means they
    are basically methods with no implementations) then how is iteration
    possible? We havent defined anything in the hasNext() method or the next()
    so how does Java automatically start iteration
    Has any one understood my question?Arent hasNext() and next() supposed
    to be methods with no body???
    If I am saying iter.hasNext(),that means hasNext() has been defined
    somewhere to iterate thru the vector?
    I am just confused regarding this issue as to how is hasNext() and next()
    being implemented as I as the programmer have not implemented them
    in my code
    Please can some one answer my question?
    Regards
    Ajay

    Thanks Will.
    Regarding the question,then why define an Iterator interface when
    the collection class implements the functionality?
    Why not define the methods hasNext() and next() in the Object
    class?
    So by default,all classes extends the Object class ,we
    cud use the hasNext() and next() method?
    No??? Or am I wrong?

  • Reconcile question: Error iterating accounts for resource:

    Guys,
    One question. While trying to reconsile my MS SQL database table it fails and I'm getting the next error message:
    Error iterating accounts for resource :
    java.lang.NullPointerException
    Any Idea what might cause this error. All other resources are reconsiling just fine...
    Thanks.
    Elger

    Unfortunately that didn't help. I deleted the whole account index just to make sure all 'links' where gone but I'm still getting the null pointer exception.
    Any more idea's?

  • Iterator Interface.A question please......respond

    I am unable to grasp the meaning of the following below :
    As we all know,Interfaces have abstract methods,(ie methods that
    have no body) and any class that implements the Interface has to
    implement the methods defined in the interface.That is,write the body for those methods.
    So far so good.
    Now coming to Collections called Vector.
    We have the 'Iterator' interface implemented by the vector class.
    The Iterator interface has the methods hasNext(),next().
    and we have the following code in the our class which iterates thru'
    the vector:
    MyClass item;
    while(iter.hasNext())
    item = (MyClass)iter.next();
    // Do something here.....
    Now we are using the methods hasNext() and next() above.
    But as they belong to the Iterator interface,(which means they
    are basically methods with no implementations) then how is iteration
    possible? We havent defined anything in the hasNext() method or the next()
    so how does Java automatically start iteration
    Has any one understood my question?Arent hasNext() and next() supposed
    to be methods with no body???
    If I am saying iter.hasNext(),that means hasNext() has been defined
    somewhere to iterate thru the vector?
    I am just confused regarding this issue as to how is hasNext() and next()
    being implemented as I as the programmer have not implemented them
    in my code
    Please can some one answer my question?
    Regards
    Ajay

    Thanks for yr reply.
    So you mean to say the the Iterator methods hasNext()
    and next()
    are being implemented by the Vector class.right?Not exactly. The Vector class defines an inner class, and it is this class that implements the Iterator interface, and so these two methods. When you write code like
    Vector myVector = new Vector();
    // code to fill myVector...
    Iterator it = myVector.iterator();the call to the iterator() method tells myVector to give you an instance of this inner class. The Vector class itself doesn't implement next() or hasNext().
    Then why define an interface with these methods at
    all?
    Why not give concrete bodies to these methods and put
    them in
    the Object Class.If you did that, then all classes would inherit them - all classes would be iterators. That wouldn't make sense, though, as clearly not all classes are meant to be used to iterate over collections of objects.
    Iterator is an interface so that a consistent API can be defined for iteration. As iterators are used in lots of different places, it is very helpful to have all of them guaranteed to have next() and hasNext() methods (amongst others). It is also very helpful to be able to call the iterator() method on any Collection class and know that the object that is returned, regardless of its implementation, will be of type Iterator.
    Then we can call them polymorphically.???But that's what you're doing - Vector and ArrayList (for example) have different implementations of Iterator, but code that iterates over them doesn't need to know that. As both return objects that implement the Iterator interface, they are interchangeable; that's polymorphism at work.

Maybe you are looking for

  • HP LaserJet 400 colorMFP M475dw scan to email problems

    Hi all! I'd very much appreciate a solution to my agony. We recently purchased a HP LaserJet 400 colorMFP M475dw multifunction printer. Now I'm trying to set it up (browser administration -> Scan --> Outgoing E-mail Profiles) to send scanworks by ema

  • Change of Plan fee

    a couple months ago my husband dropped his phone and we upgraded to the iphone5. With that came the new shared plans that we did not want to deal with but had no choice so ok...we have one. Our bill was suppose to decrease but in fact it increased. S

  • File to File Scenario: Error Occured

    The following error were displayed in the communication channel monitoring for the Sender FTP Adapter 1.An error occurred while connecting to the 11.10.10.41FTP server . The FTP server returned the following error message:  'com.sap.aii.adapter.file.

  • Spring Console extension for weblogic 10.0

    Hi, I am trying to configure spring console extension for weblogic version 10.0 . As mentioned in some documents, I am unable to find the required jars in the server lib folder, and googled to download it, but yet no success. If any one is aware of w

  • How do I XY graph two different signals each with its own y-axis on the same graph?

    I have wired an n-ch, 1 sample VI to an xy graph express VI.  I have two y-axis scales, but I only see a plot of one of the signals.  Can anyone help me understand what I am doing wrong, and how to do it correctly?  The VI as a whole may look ugly, b