[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Java List

Posted on 2017-04-10
4
Medium Priority
?
121 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
  • 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 11

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

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!

Question has a verified solution.

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

Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
When you discover the power of the R programming language, you are going to wonder how you ever lived without it! Learn why the language merits a place in your programming arsenal.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
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…
Suggested Courses
Course of the Month18 days, 18 hours left to enroll

834 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