i made this code to loop number for(int i=0;i<4;i++){ double temp[i]=Math.random() * i*10; system.out.println("Result" +i+ "=>" +temp); } output : Result 0 => 14.3 Result 1 => 11.4 Result 2 => 10.8 Result 3 => 12.4 now, i want to sort by ascending this output based on value with keep original index, so the output like this : Result 2 => 10.8 => 1 Result 1 => 11.4 => 2 Result 3 => 12.4 => 3 Result 0 => 14.3 => 4 how to do this?

Member Avatar
Member Avatar
+0 forum 7

I'm attempting to use the ObjectOutput/InputStream to write data to a file; I'm fairly certain I've got the out portion but coming back in isnt working as it should, thoughts? public static void writePersistant(ArrayList<PersistantObject> persistantRecords) { try { ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("dataout/population-record.ser")); for (PersistantObject i : persistantRecords) { oos.writeObject(i); } oos.close(); } catch (FileNotFoundException ex) { System.out.println(ex.getMessage()); System.out.println(ex.getStackTrace()); } catch (IOException ex) { System.out.println(ex.getMessage()); System.out.println(ex.getStackTrace()); } } public static void readerPersistant() { try { ObjectInputStream ois = new ObjectInputStream(new FileInputStream("dataout/population-record.ser")); Object inputObj = null; while ((inputObj = ois.readObject()) != null) { if (inputObj instanceof PersistantObject) { System.out.println(inputObj); } …

Member Avatar
Member Avatar
+0 forum 3

Hi all, I actually need to use a sorted map.So i tried using Tree Map.But the problem is that This works well with sort key having values upto 9. With more than 10 items I see abrupt results with sort key arranged in the order = 1, 10, 11,12,--------17, 2, 3, 4, 5, 6, 7, 8, 9. I even tried using Comparator for this ....But the same way it is sorted...How to make it arrange in the correct order of 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11? Please find my code below public static TreeMap sortByComparator(TreeMap …

Member Avatar
Member Avatar
+0 forum 2

The End.