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

  • Home
  • SEARCH
  • 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 6961787
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:34:33+00:00 2026-05-27T15:34:33+00:00

Im trying to put arraylists into an arraylist. Adding data to the new arrays,

  • 0

Im trying to put arraylists into an arraylist. Adding data to the new arrays, then print them in order. Im only getting errors.

Is this the right way to create an arraylist in another arraylist using a for loop?

I would also like to now how I can get data from the array in a better way then these long expresions.

My errors

    jogging.java:101: warning: [unchecked] unchecked call to add(E) as a member of the raw type java.util.ArrayList
                res.get(iter).add(new Resultat(name,time));

   jogging.java:152: warning: [unchecked] unchecked conversion found   : java.util.ArrayList required: java.util.List<T> Collections.sort(res.get(iter2));

    jogging.java:152: warning: [unchecked] unchecked method invocation: <T>sort(java.util.List<T>) in java.util.Collections is applied to (java.util.ArrayList)
                Collections.sort(res.get(iter2));

    import java.util.;
    import java.lang.;

class Resultat implements Comparable<Resultat> { String namn; double tid; public Resultat( String n, double t ) { namn = n; tid = t; } public String toString() { return namn + " "+ tid; } public int compareTo( Resultat r ) { if (this.tid < r.tid){ return -1; } else if (this.tid > r.tid){ return 1; } else if (this.tid == r.tid && this.namn.compareTo(r.namn) <= 0) { return -1; } else if ( this.tid == r.tid && this.namn.compareTo(r.namn) >= 0){ return 1; } else {return 0;} } } public class jogging { public static void main( String[] args ){ int runners = scan.nextInt(); int competitions = scan.nextInt(); //create arraylist with arraylists within ArrayList <ArrayList> res = new ArrayList<ArrayList>(); for(int i = 0; i <= competitions; ++i){ res.add(new ArrayList<Resultat>()); } for (int i = 0; i < runners; i++){ String name = scan.next(); //runs the person made int antalruns = scan.nextInt(); for(int n = 0; n <antalruns; n++){ //number of the run int compnumber = scan.nextInt(); //time for the run double time = scan.nextDouble(); for(int iter = 0; iter < res.size(); ++iter){ res.get(iter).add(new Resultat(name,time)); } } } for(int iter2 = 0; iter2 < res.size(); ++iter2) { Collections.sort(res.get(iter2)); System.out.println(iter2); for(int it = 0; it < res.get(iter2).size(); ++it) { System.out.println(res.get(iter2).get(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-27T15:34:33+00:00Added an answer on May 27, 2026 at 3:34 pm

    The unchecked warnings are because you haven’t declared the generic types of the 2nd ArrayList. Try using

    ArrayList <ArrayList<Resultat>> res = new ArrayList<ArrayList<Resultat>>();
    

    Yes, it’s a bit tedious. 🙁

    Also, most think it good practice to use the interface (e.g. List, not ArrayList) on the left side, just in case you change your mind as to the implementation in the future. e.g.

    List <List<Resultat>> res = new ArrayList<ArrayList<Resultat>>();
    

    ADDED

    Also, you could simplify your compareTo() method. For comparing the tids, look at Double.compare(). Something like:

       public int compareTo( Resultat r ) {
    
          int compare = Double.compare(tid, r.tod);
          if (compare != 0)
             return compare;
          else
             return namn.compareTo(r.namn);
       }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I trying to put my Mac's data in order. I have many rc-files at
I'm trying put an if statement directly into a select field in rails, with
Im trying to put an html embed code for a flash video into the
I am trying to put some distributed caching into play, I'm using this indeXus.Net
I'm trying to put a Message back into an MSMQ when an exception is
I am trying to put a requirement together for a new environment to consist
I am trying to make Task parcelable to put into an bundle to pass
I am trying put ads inside my blogger post & i want my data
I am trying to put all of my strings into the resource file, something
I'm trying to put different images (.jpg , .png) dynamically into a ListView from

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.