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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T06:47:52+00:00 2026-05-24T06:47:52+00:00

how can I make array of ArrayList or Pair Class which I made myself

  • 0

how can I make array of ArrayList or Pair Class which I made myself at the code below.

ex1)

import java.util.*;

class Pair{
  static int first;
  static int second;
}

public class Main{
  public static void main(String[] args){
    Vector<Pair>[] v = new Vector<Pair>[100](); //this gives me an error
  }
}

1.why the code above gives me an error?
2.my goal is to make an array of vector so that each index of vector holds one or more Pair classes. How can I make it?

another example) : array of ArrayList

import java.util.*;

public class Main{
  public static void main(String[] args){
    ArrayList<Integer> arr = ArrayList<Integer>(); //I know this line doesn't give error
    ArrayList<Integer>[] arr = ArrayList<integer>[500]; // this gives me an error
  }
}

3.why does the code above give me an error?
4.my goal is to make an array of ArrayList so that each index of Array has ArrayList/Queue/Vector/Deque whatever. How can I make it?

  • 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-05-24T06:47:53+00:00Added an answer on May 24, 2026 at 6:47 am

    The syntax you have used is not what Java uses. If you want to have an array of ArrayLists then do:

    ArrayList[] arr = new ArrayList[100];
    
    for(int i=0; i<arr.length; i++)
    {
        arr[i] = new ArrayList<Pair>(); // add ArrayLists to array
    }
    

    Here the type argument <Pair> specifies that the ArrayList should contain items of type Pair. But you can specify any type you wish to use. The same goes for ArrayList, you could replace ArrayList with Vector in the example.

    It would be best to use an ArrayList instead of an array in the example. Its much easier to maintain without worrying about the changing length and indexes.

    Hope this helps.

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

Sidebar

Related Questions

How can I make this code work? class Meta @array = [:a,:b] def self.method_missing(name,
I have two questions: 1) How can I make an array which points to
How can i make an array like below through a loop? The text will
For an XNA engine I'm trying to make myself, I want an array/arraylist of
I have an array, and I want to make a hash so I can
I've managed to make some single dimension array lists but I can't figure out
How can I make an array that handles some of my images so that
I need to make array in a arraylist or in a list, I used
I try hard to find the problem in this Java code, but I can't
How can i sort ArrayList in java without using comparator.? I have already used

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.