Hi Jack and welcome to bytes.com!
Java doesn't have an own type for records and Strings aren't fixed length either. The closest to the above would be a
Bean with
String members or, if you insist on fixed lengths, char arrays. A bean is a very basic Java class with private variables as well as getter and setter functions for those variables. Of course, you could enforce a certain length in those setter functions.
Here's a truncated example:
- public class hdrmail1rec {
-
private String hdrcust;
-
// ...
-
-
public String getHdrcust() {
-
return hdrcust;
-
}
-
-
public void setHdrcust(String hdrcust) {
-
if(hdrcust.length() > 20) {
-
this.hdrcust = hdrcust.substring(0,21);
-
} else {
-
this.hdrcust = hdrcust;
-
}
-
}
-
// ...
-
}
In theory, you could make the String variables public and do without the getters and setters; this is however considered bad practice due to security reasons (as any class could then access the variables without you having any control over it). Also, many libraries and frameworks follow the convention of having getters and setters.