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 8938829
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:43:17+00:00 2026-06-15T10:43:17+00:00

Ok i need some help with a little syntax problem. I have a class

  • 0

Ok i need some help with a little syntax problem. I have a class and i want it to put it into an arraylist, and populate the arraylist using a for loop.
Here is an example of what i want:

    public class w{
    int x;
    int y;
    }
    Arraylist m = new Arraylist();
    for(int i=0; i<n;i++)
  {
          m[i].add(w.x);
          m[i].add(w.y);

  }

Yes the code isn’t functioning its just an example of what i want it to do. I don’t know the syntax and I want an arraylist with classes that can be retrieved by giving the i and get the both variables only by that ‘i’;
Any help will be apreciated. Thank you very much for your time, sorry for the lousy description but i can’t be more specific.

  • 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-15T10:43:18+00:00Added an answer on June 15, 2026 at 10:43 am

    It’s not clear what you’re trying to accomplish, but perhaps this will be enough of a guide as to how to use ArrayList properly. I changed your class name from w to W to match the usual Java coding conventions.

    public class W {
        int x;
        int y;
        public W(int x, int y) {
            this.x = x;
            this.y = y;
        }
    }
    
    ArrayList<W> m = new ArrayList<W>(); // can be 'new ArrayList<>()` in Java 7
    m.add(new W(1, 2));
    m.add(new W(5,-3));
    // etc.
    
    for (int i=0; i<m.size(); i++) {
        W w = m.get(i);
        System.out.println("m[" + i + "]=(" + w.x + "," + w.y + ")");
    }
    
    for (W w : m) {
        System.out.println("next W: (" + w.x + "," + w.y + ")");
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I ran into a little problem and need some help: If I have an
I need some help with overlaying views using the prism framework.Its a little more
i need some help with a little problem that occurred today. To show the
I need a little help with some Emacs syntax highlighting troubles. I'd like to
I have very little experience with asp.net and need some help with a presumably
I have a little question. I want to put some strings in an String[].
I'm not a lot into HTML and I need some help. I've a little
Need some help... I have jasperserver 4.1 installed on my ubuntu. It runs via
Need some help with Activerecord Querying in a has_many :through association. Model: Job class
Need some help, please. I have a line of horizontal thumbnails loaded as ONE

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.