Skip to content

Tag: list

How to put multiple values into a json in java

I’m trying to return a list of values from JDBC but multiple columns of the database to solve this I just made a JSON object to make something like this The issue is im getting this error WARN 43953 — [nio-1900-exec-1] .w.s.m.s.DefaultHandlerExceptionResolver : Resolved [org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representation] What I’ve tried I’ve tried using a hash map but

List of int array in Java

How do I print the contents of a List that contains a primitive type int object in it? Prefer answers to print this in one line. This is the code I have. This will give me [0,1] but I am looking for {[0,1],[2,3]} Answer The following one-liner can meet your requirement: It uses the positive lookbehind and positive lookahead regex

How to i iterate and compare two lists

Here I’m trying to compare two lists position wise that is the first element from list1 has to be compared with only the first element of list2 and if they are equal it should be replaced with the empty string in the output list and if they are different the element in the second list has to be updated in

How to randomize ArrayList without using Collections.swap()?

I was asked to create a method that randomly rearranges my list which contains arrays. The list contains multiple persons and their names and surnames. My question is how do I move a person (array containing two elements name and surname inside the list) to a different index without using the method swap()? Because our list does not support that

Append list according to their size in Java

I am trying to append two list according to their size. With list with bigger size in front. I have few lists like this. List<Pair<Double, String>> masterList = new ArrayList<>(); and this is the working Java code that I tried first – with a simple if else loop: I am fairly new to the Java, so I was studying about

Merge an List of Object and an Object to a new array in Java [closed]

Closed. This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 10 months ago. Improve this question I have List<BigInteger> sample1 = Lists.newArrayList(BIGINTEGER1, BIGINTEGER2,BIGINTEGER3); I have to create new List sample2 with one more value BIGINTEGER4 along with sample1 list: How can