Solved

Java List

Posted on 2017-04-10
4
89 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 250 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 250 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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

A short article about problems I had with the new location API and permissions in Marshmallow
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
Progress
Starting up a Project

696 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