Question: I want to sort my second column by ascending order using 2D arrays by reading in a CSV file. How do I do so? (Using

I want to sort my second column by ascending order using 2D arrays by reading in a CSV file. How do I do so? (Using JAVA)

import java.io.*;

import java.util.*;

public class artists {

public static void main(String[] args) throws IOException {

// reads in filw

Scanner sc = new Scanner(new FileReader("csvFiles.csv"));

int count = 0;

// create 2D array

String[][] arr = new String[5][202];

// checking each line while there is a line

while (sc.hasNextLine()) {

String str = sc.nextLine();

// splitting the comma

String[] categories = str.split(",");

// System.out.println(str);

// loops through the array and grabs the elements

for (int i = 0; i < categories.length; i++) {

arr[count][i] = categories[i];

}

// prints the ar

System.out.println(categories[2]);

}

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!