Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating struct like data structure in Java

I am new to Java and I am trying to find out a way to store information like a struct in C. Say for example I want to have a program hire employees. It would take from the user a first name, last name, and id number and would store it. The user could then view that information based off a condition (if the database had more than 1 employee for example). Can any suggest the best way for doing this?

like image 479
bardockyo Avatar asked Feb 10 '13 02:02

bardockyo


People also ask

Can you create a struct in Java?

Yes, Java doesn't have a struct/value type yet. But you have good news as well. Project JUnion delivers struct types for Java programming language. So you can use Struct types in java by using Project JUnion plugin by annotating a class with @Struct annotation.

What is the Java equivalent of a struct?

A struct is the Java equivalent of a C++ struct. Use structs to group domain definitions and other struct classes to form programmatic record definitions. Use struct classes as arguments to operations of entity and process classes.

How do you create a structure in data structure?

Select Data Structure on the Add Object form and click the OK button. Enter the name, description, and product code of a data structure. For a regular data structure, select Regular Data Structure. Complete the Add Object form and select Regular Data Structure, then click the OK button.

Is Java good for data structure?

Which programming language is best for data structures and algorithms? Data structures and algorithms are not language specific and hence you can use any language be it JavaScript, C, C++, Java or Python. You should feel comfortable with the syntax of the language and you are good to go.


1 Answers

In Java 16 there are Records (JDK Enhancement Proposal 395):

public record Employee(String firstName, String lastName, String id) {
}

This comes with a canonical constructor, field accessors, hashCode(), equals() and toString() implementations.

like image 57
Markus Pscheidt Avatar answered Sep 30 '22 13:09

Markus Pscheidt