Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions