Skip to content
Advertisement

Tag: arrays

How to sort a list of months with years

I have a list of months with years such as: [12-2014,11-2012,5-2014,8-2012] and I have to sort them with the most recent on top (or the latest date on top) eg. [12-2014,5-2014,11-2012,8-2012] . Does anybody have any idea on how to do this in Java efficiently? EDIT: The class YearMonth is not available, I’m on Java 7 Answer Since you are

ByteBuffer to int array (each byte)

Related to question byte array to Int Array, however I would like to convert each byte to an int, not each 4-bytes. Is there a better/cleaner way than this: Answer I’d probably prefer

Java, comparing a Linked List to an Array

Working on a Java program that will read in two different passages, convert both strings to arrays of strings for each word, and then String One to a linked list, which will promptly be sorted into alphabetical order. After the list has been sorted, I get confused. I have a for loop written to get the length of array2 to

Transposing a matrix from a 2D array

I’m self teaching myself some java and I’m stuck on creating a 2D array that initializes it with random values and then creates the transpose of the array. An example output is: Original matrix Transposed matrix ^ Should be the final output. Some help with the code would appreciated! I would like to code to generate error messages if the

The object-oriented approach to a many-to-many relationship

I’m battling at the moment in trying to understand how to approach this issue in an object-oriented way. With a many-to-many relationship such as Students-Subjects, where each student gets a mark for a certain subject, assuming the following: I want to be able to display all the marks for a given student. I want to display all the marks from

Finding closest number to 0

I have an array of integers, and I need to find the one that’s closest to zero (positive integers take priority over negative ones.) Here is the code I have so far: Currently I’m getting a result of -2 but I should be getting 2. What am I doing wrong? Answer Sort the array (add one line of code) so

Advertisement