I am writing a program that allows the user to enter up to 1000 String elements from a disk file. This happens in another String array method, it then copies them into another array and then bubblesorts them in the method below. However, I am getting an error due to my new array length expecting 1000 elements and the disk file only putting in, lets say, 50. I think the best way to solve my problem is to create an array that has the same length as the Strings in the disk file. However, I am not sure how to create another array the length of the Disk file input. Any help would be great.
public static String[]bubbleSort(String[] inputArr) {
String[] Array2 = new String[inputArr.length];
for(int i=0;i<inputArr.length;i++)
Array2[i] = inputArr[i];
for (int i = 0; i<Array2.length; i++)
{
for (int j = 0; j<Array2.length-1; j++)
{
if (Array2[j].compareTo(Array2[j+1]) > 0)
{
String temp = Array2[j];
Array2[j] = Array2[j+1];
Array2[j+1] = temp;
}
}
}
return Array2;
}