Skip to content
Advertisement

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 its object using method show() I

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 type

Cannot invoke ” ” because array is null

I need to add information about 2 actors such as their name, address and age and have done so without arrays easily but it’s necessary, I keep getting the error “Cannot invoke “TestActor.setName(String)” because “actors[0]” is null at TestMain.main(TestMain.java:5)” This is just a test main I’m using to test it ”’ And this is the actor class I’m using that

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 practice as

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 can try if you

Advertisement