Win a copy of TensorFlow 2.0 in Action this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

Display arraylists of different sizes side by side

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, everyone.
I'm a beginner and it's my first appearance.
I want to display 3 small arraylists side by side, but I don't know how.
I much appreciate your help.

 
Marshal
Posts: 70689
288
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

Please explain what you want the display to look like.

You have declared your Lists wrongly, I am afraid. 1: Declare them as List, nor ArrayList. 2: Make sure to maintain the generics. You are using a raw type.The <> is interpreted as, “same generic type as in the declaration”.
 
Adham Houssam
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for your answer.
I want to display them like this

2    9    23
4    15   37
6    21
8

As for the rest of your answer, I'm still reading it, and trying to understand it.
     
 
Adham Houssam
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh, sorry, I didn't see your code.
Now, I understand there's List, and how to declare it.
 
Saloon Keeper
Posts: 7393
66
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The number of rows in your display is the MAX size of each of your lists. The columns are 1 for each list. Loop through each row and loop through each list. If the row for the list of the current column is < size, then print the number, else, print the equivalent number of spaces.

If you use a normal print() call your columns will appear wobbly. Use printf() instead.
or else print 8 spaces if rows >= size.
 
What a show! What atmosphere! What fun! What a tiny ad!
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic