?
Solved

Java List

Posted on 2017-04-10
4
Medium Priority
?
100 Views
Last Modified: 2017-04-14
Hello,
I'm not familiar with ArrayList.  I'm currently looking/searching, yet if you know; I need for the ArrayList to hold three values.  They can all be strings.  Better yet; <String, String, double>   Is this possible with an ArrayList?;

package StudentClass;
import java.util.*; 

public class StudentRecords{
	
	public static void main(String[] args) {

		  ArrayList<String/*, String, String*/> StudRecord = new ArrayList<String/*, String, String*/>();

		  StudRecord.add("Will"/*, "reading", "A"*/);
		  /*obj.add("Harry");
		  obj.add("Chaitanya");
		  obj.add("Steve");
		  obj.add("Anuj");*/

		  //System.out.println("Currently the array list has following elements:"+obj);

		  /*Add element at the given index*/
		  //obj.add(0, "Rahul");
		  StudRecord.add("Justin"/*, reading, "B"*/);

		  /*Remove elements from array list like this*/
		  //obj.remove("Chaitanya");
		 // obj.remove("Harry");

		  System.out.println("Current array list is:"+StudRecord);

		  /*Remove element from the given index*/
		 // obj.remove(1);

		  System.out.println("Current array list is:"+StudRecord);
	   }

}

Open in new window

0
Comment
Question by:chima
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 28

Accepted Solution

by:
dpearson earned 1000 total points
ID: 42087353
It's always ArrayList<Type>

for one Type.

That however can be a class that contains the three values String, String, double.

Make sense?

Doug
1
 

Author Comment

by:chima
ID: 42087388
Doug, it does, let me try it, thanks
0
 
LVL 10

Assisted Solution

by:Jeffrey Dake
Jeffrey Dake earned 1000 total points
ID: 42087441
dpearson is correct and looking at what you are trying to do StudentRecord should probably be its own class the represents a student.  I would also recommend intead of using "A", "B", "C" which I am assuming is a grade, you might want to look into using an Enum for that so that you can predefine allowed values.
0
 

Author Comment

by:chima
ID: 42087510
Jeff, I'll take a look at enum.
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Starting up a Project
Suggested Courses
Course of the Month8 days, 18 hours left to enroll

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question