I need an algorithmic help to convert an input Array object to ArrayList<List<Integer>> object?

Emanuel Wilcon

I need an algorithmic help to convert an input array in Java having this content : {5,6,3,2,4,7}

To this format :
[[2, 3], [3, 4], [4, 5], [5, 6], [6, 7]].

RIEquation Consultancy
List<Integer> arrayList = new ArrayList<>(Arrays.asList(5,6,3,2,4,7));
Collections.sort(arrayList);
System.out.println("Input:"+arrayList);
List<List<Integer>> list = new ArrayList<List<Integer>>();
list.add(0, new ArrayList<Integer>(Arrays.asList(arrayList.get(0),arrayList.get(1))));
list.add(1, new ArrayList<Integer>(Arrays.asList(arrayList.get(1),arrayList.get(2))));
list.add(2, new ArrayList<Integer>(Arrays.asList(arrayList.get(2),arrayList.get(3))));
list.add(3, new ArrayList<Integer>(Arrays.asList(arrayList.get(3),arrayList.get(4))));
list.add(4, new ArrayList<Integer>(Arrays.asList(arrayList.get(4),arrayList.get(5))));
System.out.println("Output:"+list);

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

convert an arrayList<Object[]> into a nested array

How do i convert a json array object of an object into a java 8 optional list of that object

Why do I need to recast an integer array accessed from within an object array in Java?

Input Object into an array as a List in Java

Convert String to Integer(Object) Array Java

Convert an ArrayList to an object array

Why can't Java convert an ArrayList<TreeSet<Integer>> into a List<Set<Object>>?

Convert ArrayList<Object[]> to Object[][]

How do I convert an object array to an object list

I want to convert Object Array to Object with JavaScript

Need to convert object to array for FlatList in React Native

how do I convert an object to an array list in JS

Convert List<Object[]> Array into an object

(Javascript) Need help converting an object to an array

Need help in reducing array of object into a single sum

Convert list object into array

I have JSON Object, with this object i need to find the ID Number of "xxxEmployeeCategory "T" and list the list in an Array

Convert an object into list or array MVC

Trying to convert List<object> to an array

How can I convert this list of pairs into an object that contains an array of arrays?

Cannot convert ArrayList<ArrayList<Integer>> to ArrayList<ArrayList<Object>>

Need help adding an object to my array list, whenever it changes

Need help getting the value of object length in array

[help]ValueError: Failed to convert a NumPy array to a Tensor (Unsupported object type list)

trying to convert array of list to object?

Convert an array of object to a list of a class

Need help to convert nested array object of array object (2 level) to array of object (1 level) in ReactJS TypeScript

I need help to reorder array.object considering a specific element

I need some help trying to serialize an object array

TOP Ranking

  1. 1

    Failed to listen on localhost:8000 (reason: Cannot assign requested address)

  2. 2

    Loopback Error: connect ECONNREFUSED 127.0.0.1:3306 (MAMP)

  3. 3

    How to import an asset in swift using Bundle.main.path() in a react-native native module

  4. 4

    pump.io port in URL

  5. 5

    Compiler error CS0246 (type or namespace not found) on using Ninject in ASP.NET vNext

  6. 6

    BigQuery - concatenate ignoring NULL

  7. 7

    ngClass error (Can't bind ngClass since it isn't a known property of div) in Angular 11.0.3

  8. 8

    ggplotly no applicable method for 'plotly_build' applied to an object of class "NULL" if statements

  9. 9

    Spring Boot JPA PostgreSQL Web App - Internal Authentication Error

  10. 10

    How to remove the extra space from right in a webview?

  11. 11

    java.lang.NullPointerException: Cannot read the array length because "<local3>" is null

  12. 12

    Jquery different data trapped from direct mousedown event and simulation via $(this).trigger('mousedown');

  13. 13

    flutter: dropdown item programmatically unselect problem

  14. 14

    How to use merge windows unallocated space into Ubuntu using GParted?

  15. 15

    Change dd-mm-yyyy date format of dataframe date column to yyyy-mm-dd

  16. 16

    Nuget add packages gives access denied errors

  17. 17

    Svchost high CPU from Microsoft.BingWeather app errors

  18. 18

    Can't pre-populate phone number and message body in SMS link on iPhones when SMS app is not running in the background

  19. 19

    12.04.3--- Dconf Editor won't show com>canonical>unity option

  20. 20

    Any way to remove trailing whitespace *FOR EDITED* lines in Eclipse [for Java]?

  21. 21

    maven-jaxb2-plugin cannot generate classes due to two declarations cause a collision in ObjectFactory class

HotTag

Archive