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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T21:47:14+00:00 2026-06-04T21:47:14+00:00

I’ve heard of using a two dimensional array like this : String[][] strArr; But

  • 0

I’ve heard of using a two dimensional array like this :

String[][] strArr;

But is there any way of doing this with a list?

Maybe something like this?

ArrayList<String><String> strList;

And using something like this to add to it?

strList.add("hey", "hey");

Any way of doing something like this? Any help appreciated.

It would be good if there is because i am currently putting strings into two differrent ArrayList’s in pairs.

  • 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-04T21:47:15+00:00Added an answer on June 4, 2026 at 9:47 pm

    You would use

    List<List<String>> listOfLists = new ArrayList<List<String>>();
    

    And then when you needed to add a new “row”, you’d add the list:

    listOfLists.add(new ArrayList<String>());
    

    I’ve used this mostly when I wanted to hold references to several lists of Point in a GUI so I could draw multiple curves. It works well.

    For example:

    import java.awt.BasicStroke;
    import java.awt.Color;
    import java.awt.Dimension;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import java.awt.Point;
    import java.awt.RenderingHints;
    import java.awt.Stroke;
    import java.awt.event.MouseAdapter;
    import java.awt.event.MouseEvent;
    import java.util.ArrayList;
    import java.util.List;
    import javax.swing.*;
    
    @SuppressWarnings("serial")
    public class DrawStuff extends JPanel {
       private static final int PREF_W = 400;
       private static final int PREF_H = PREF_W;
       private static final Color POINTS_COLOR = Color.red;
       private static final Color CURRENT_POINTS_COLOR = Color.blue;
       private static final Stroke STROKE = new BasicStroke(4f);
       private List<List<Point>> pointsList = new ArrayList<List<Point>>();
       private List<Point> currentPointList = null;
    
       public DrawStuff() {
          MyMouseAdapter myMouseAdapter = new MyMouseAdapter();
          addMouseListener(myMouseAdapter);
          addMouseMotionListener(myMouseAdapter);
       }
    
       @Override
       public Dimension getPreferredSize() {
          return new Dimension(PREF_W, PREF_H);
       }
    
       @Override
       protected void paintComponent(Graphics g) {
          super.paintComponent(g);
          Graphics2D g2 = (Graphics2D) g;
          g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, 
                RenderingHints.VALUE_ANTIALIAS_ON);
          g2.setStroke(STROKE);
          g.setColor(POINTS_COLOR);
          for (List<Point> pointList : pointsList) {
             if (pointList.size() > 1) {
                Point p1 = pointList.get(0);
                for (int i = 1; i < pointList.size(); i++) {
                   Point p2 = pointList.get(i);
                   int x1 = p1.x;
                   int y1 = p1.y;
                   int x2 = p2.x;
                   int y2 = p2.y;
                   g.drawLine(x1, y1, x2, y2);
                   p1 = p2;
                }
             }
          }
          g.setColor(CURRENT_POINTS_COLOR);
          if (currentPointList != null && currentPointList.size() > 1) {
             Point p1 = currentPointList.get(0);
             for (int i = 1; i < currentPointList.size(); i++) {
                Point p2 = currentPointList.get(i);
                int x1 = p1.x;
                int y1 = p1.y;
                int x2 = p2.x;
                int y2 = p2.y;
                g.drawLine(x1, y1, x2, y2);
                p1 = p2;
             }
          }
       }
    
       private class MyMouseAdapter extends MouseAdapter {
          @Override
          public void mousePressed(MouseEvent mEvt) {
             currentPointList = new ArrayList<Point>();
             currentPointList.add(mEvt.getPoint());
             repaint();
          }
    
          @Override
          public void mouseDragged(MouseEvent mEvt) {
             currentPointList.add(mEvt.getPoint());
             repaint();
          }
    
          @Override
          public void mouseReleased(MouseEvent mEvt) {
             currentPointList.add(mEvt.getPoint());
             pointsList.add(currentPointList);
             currentPointList = null;
             repaint();
          }
       }
    
       private static void createAndShowGui() {
          JFrame frame = new JFrame("DrawStuff");
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frame.getContentPane().add(new DrawStuff());
          frame.pack();
          frame.setLocationRelativeTo(null);
          frame.setVisible(true);
       }
    
       public static void main(String[] args) {
          SwingUtilities.invokeLater(new Runnable() {
             public void run() {
                createAndShowGui();
             }
          });
       }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
For some reason, after submitting a string like this Jack’s Spindle from a text
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string
I have some data like this: 1 2 3 4 5 9 2 6
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has

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.