

How to get specific object values from java & lt; List & gt; and conve...
source link: https://www.codesd.com/item/how-to-get-specific-object-values-from-java-list-and-convert-to-string-array.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

How to get specific object values from java & lt; List & gt; and convert to String Array
I need your assistant and help in getting the values of an object in a Java and then to convert the output to String Array so I can pass it to a procedure. Here is my Java class:
public class PendingRequests {
private String requestDate; //Getter & Setter
private String requestNo; //Getter & Setter
private String employeeName; //Getter & Setter
}
And in the bean I am defining a List called "selectedRequests":
private List<PendingRequests> selectedRequests;
The selectedRequests is having values and I need to get the values of the requestNo from it and then convert it to String Array. With my attempts, I was only able to print them in the console by using the below code:
for(Object obj : selectedRequests){
System.out.println("Obj = "+((PendingRequests)obj).getRequestNo());
But is it the correct way and what should I do next?
String[] requestNos = new String[selectedRequests.size()];
for (int i = 0; i < selectedRequests.size(); i++) {
requestNos[i] = selectedRequests.get(i).getRequestNo();
}
And here is the Java 8 version of the same thing:
String[] requestNos = selectedRequests
.stream()
.map(r -> r.getRequestNo())
.toArray(String[]::new);
Recommend
-
8
Returning a Java Object List in RabbitMQ RPC In this post we will build on returning Java Objects in RabbitMQ RPC by returning an Object List. What w...
-
10
SQL Find historical sensor values at specific dates advertisements I have a database that has a vessel pressure that is trended every 30 sec...
-
9
Unique PostgreSQL index for a set of specific values advertisements Let's say there is a table AVATARS and among other columns it has us...
-
9
How to write an SQL query to identify duplicate values in a specific field? advertisements This is the table I'm working...
-
5
Generating a random numpy ndarray of 0 and 1 with a specific range of 1 values Data Science Stack Exchange is a question and answer site for Data science professionals, Machine Learning specia...
-
10
Count the number of duplicate values on a column for specific values from another column in MySQL? advertisements I've...
-
16
Stop Leaving Money on the Table: 5 Proven Psychology Tips to Catapult Your Conversions Words sell. Injecting psychology into them will help boost your conversion rate and make you more money. ...
-
12
Introduction ‘Hey, Siri, ‘Hey, Google,’ and ‘Alexa’ are some common voice assistants we use on an everyday basis. These fascinating conversational bots use Natural Language Understanding to understand the inputs. NLU is a subset...
-
9
Next →Temenos Banking Cloud Scales to Record High Transactions with MongoDB Atlas and Microsoft Azure Banking used to be a somewhat staid, hyper-conservative industry, seemingly evolving over eons. B...
-
7
[Submitted on 28 Mar 2024] Improving the Bit Complexity of Communication for Distributed Convex Optimization View PDF...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK