Skip to content

Tag: arrays

Object array with variable from another class

Worksheet Question: The question said to declare an array of 5 objects of the class Node in the main Class – I managed to this as shown below But then the question continues populate the array by objects with seqNo values assigned to 1,2,3,4,5 respectively. Then traverse the array and print the list of …

How to process object with map for CSV output

I have a set of below Objects, which i need to write to CSV: Above set can have a map with two, three or four values. Output of CSV required: I started with below snippet to print out: But above is creating a two column csv with userId and behaviours printing all map object behaviours. How to achieve above ty…

Remove Alternate Elements from ArrayList in java 7

I have an array of String containing below elements Now what I want to do I need to remove all the decimal value in string format like 5.0,5.5 and 6.0 so my final array should contain elements 99,100,101 so what I’d done so far is show in below code I have hardcoded the values which is quite bad practic…

Sort arrays using lambda

I want revers-sort java8. I don’t want use stream. Here is an example: I want it like this: {5, 4, 3, 2, 1}; So my code is this But I get an error message: Operator ‘-‘ cannot be applied to ‘T’, ‘T’ How can I reverse sort and sort? Is there a better way? Answer You ca…