Solved

Java List

Posted on 2017-04-10
4
34 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 27

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
ejb example issues 3 52
ejb entity bean example issue 2 25
Eclipse with various Java releases 7 47
Programming Codes 2 41
Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
This video teaches viewers about errors in exception handling.

756 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