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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:51:22+00:00 2026-05-27T05:51:22+00:00

I have some ArrayList s declared. Some of them are ArrayList<Integer> and other are

  • 0

I have some ArrayLists declared. Some of them are ArrayList<Integer> and other are ArrayList<Double>.

I want to get them from another class, so I wrote a method:

private ArrayList<Double> list1, list2;
private ArrayList<Integer> list3;

    public ArrayList getList(String nameOfList){
        ArrayList myList = new ArrayList();
        if(nameOfList.equals("list1")) myList = list1;
        else if(nameOfList.equals("list2")) myList = list2;
        else if(nameOfList.equals("list3")) myList = list3;
        return myList;
    }

This compiles, but throws me some warnings:

*ArrayList is a raw type. References to generic type ArrayList<E> should be parameterized* in the method above, and *Type safety: The expression of type ArrayList needs unchecked conversion to conform to List<? extends Number>* when calling the method from here:

    XYSeries series = new SimpleXYSeries(data.getList("list1"), data.getList("list2"), "My chart");

where SimpleXYSeries is a chart whose constructor expects to be getting **(List<? extends Number>, List<? extends Number>, String)**.

Which is the right way to do what I’m intending to do?

  • 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-27T05:51:23+00:00Added an answer on May 27, 2026 at 5:51 am

    Use multiple methods instead of one god method.

    This is poor design to have one getList method that uses a String to select a member. Instead, there should be multiple methods – one for each list. Then each method can return the type appropriate to its list.

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

Sidebar

Related Questions

I have some data stored as ArrayList . And when I want to backup
In my widget class that extends extends AppWidgetProvider I have some static final ArrayLists
I have some objects in an ArrayList, and I want to perform collision detection
I have an arraylist (eg: h1) contain some urls. eg: http://www.google.com,http://www.yahoo.com,http://www.xyz.com ,..... How can
I have a method that returns an IEnumerable<KeyValuePair<string, ArrayList>> , but some of the
I have some ASP.NET web services which all share a common helper class they
I have some classes layed out like this class A { public virtual void
I have some arraylist string with keyword inside like that ! A windows is
I have some classes and I'm trying to fill the objects of this class.
I have some problem with @OneToMany and @ManyToOne annotations. I have two class Suite

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.