Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8970577
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:44:42+00:00 2026-06-15T17:44:42+00:00

I am trying to use a foreach to select a Creature from an existing

  • 0

I am trying to use a foreach to select a Creature from an existing player, the Creature exists in the Creature Vector under m_creature however I can’t workout the format of the foreach in Java.

I have written the code as I would write it in C# and I was hoping someone could point out the differences that I should apply to have this working in my Java application. I have been using Vectors instead of lists.

public List<Creature> SelectCreature(String Name)
    {
        List<Creature> foundCreature = new List<Creature>();

        //For the customer name that equals what has been searched...
        foreach (Creature c in m_creature)
        {
            //
            if (c.CreatureName.Equals(Name, StringComparison.OrdinalIgnoreCase))
                foundCreature.Add(c);
        }

        return foundCreature;
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T17:44:43+00:00Added an answer on June 15, 2026 at 5:44 pm

    The foreach command in java uses the same old for keyword:

    public List<Creature> SelectCreature(String Name)
    {
        // List is an interface, you must use a specific implementation
        // like ArrayList:
        List<Creature> foundCreature = new ArrayList<Creature>();
    
        //For the customer name that equals what has been searched...
        for ( Creature c: m_creature)
        {
            //
            if (c.CreatureName.equalsIgnoreCase(Name))
                foundCreature.add(c);
        }
    
        return foundCreature;
    }
    

    It would serve you well to consult the Java API, as well as to use an IDE with code completion and object property listing, such as Eclipse.

    Also, unlike C#, notice that common practice in Java is to have object methods be lower camel case, so the list method is add, and the comparison method is equals, as pointed out in the comments.

    Useful links:
    String API

    for statement

    List API

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to use CheckBoxes within a GridView's TemplateField to select multiple entries from
I'm trying to use the powershell command select-xml to select data from an xml
I'm trying to use a foreach loop for an array of objects. Inside of
I'm trying to use the foreach loop in an Ant script but I get
I am trying to use the MethodInfo MakeGenericMethod as follows: foreach (var type in
I'm trying use mod_rewrite to rewrite URLs from the following: http://www.site.com/one-two-file.php to http://www.site.com/one/two/file.php The
I'm trying to use scandir to display a select list of folders listed in
I am trying to do use .Select extension method on ListView.SelectedItems which is SelectedListViewItemCollection
I am trying to use this code on Windows 2000: foreach (Process p in
I'm trying to use the Predicate from Albahari to create a TSQL statement like:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.