In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces the relevant knowledge of how to write the code that Java stores student information, the content is detailed and easy to understand, the operation is simple and fast, and it has a certain reference value. I believe you will gain something after reading this Java code to store student information. Let's take a look.
I. introduction of the collection
The collection in Java is under the java.util package and is a container dedicated to storing objects.
Features of the collection:
The collection can only hold objects, and if it holds an int data type, it is automatically converted to an Integer object.
What is stored in the collection is the reference to the object, not the object itself. So, the collection is a reference to the object, and the object itself is still in heap memory.
Collections can store an unlimited amount of data of different types.
II. Specific application
First, define a student object:
Public class Student {/ / declare the student's attribute name, age and gender String name; Integer age; String gender; / / Construction method public Student (String name, Integer age, String gender) {this.name = name; this.age = age; this.gender = gender @ Override public String toString () {return "Student [name=" + name + ", age=" + age + ", gender=" + gender + "]";}}
Second, create several student objects, create a collection, add the student object to the collection, and print out the information about each student in the collection through the overridden toString () method.
Import java.util.ArrayList;import java.util.List;public class ListTest {public static void main (String [] args) {/ / create student objects Student s1=new Student ("a", 19, "male"); Student s2=new Student ("b", 18, "female"); Student s3=new Student ("c", 21, "female"); Student s4=new Student ("d", 20, "male") / / create a collection List a1=new ArrayList (); / / add student objects to the collection a1.add (S1); a1.add (S2); a1.add (S3); a1.add (S4); System.out.println ("traverse the collection and print information about each student"); for (int I = 0; I < a1.size () ) {System.out.println (a1.get (I). ToString ());} this is the end of the article on "how to write the code for Java to store student information". Thank you for reading! I believe that everyone has a certain understanding of the knowledge of "how to write the code for storing student information in Java". If you want to learn more, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.