title: How to find nearest smaller and larger number in Array in java?
body: <p>How can I find the nearest smaller and larger number in an <code>Array</code>?</p>
  
  <p>I have the list of numbers:</p>
  
  <pre><code>[3.4, 5.8, 1.2, 7.9, 9.6, 2.7, 6.2, 4.7, 0.6, 4.1] 
  </code></pre>
  
  <p>and I want to find the just smaller and larger than 5.0 from the array. In this case, I want the nearest smaller number which is 4.7 and nearest larger 5.8 to 5.0.</p>
  
  <p>is it possible without sorting? because I have to arrays. in one array I have x-axis values and in another array, i have yAxis value. If I sort the array, then I will not be able to get the corresponding y values for x.</p>