Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

convert arraylist to csv file java

import java.util.ArrayList;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.File;
import java.io.IOException;
class test
{
    public static void main(String arg[])throws IOException
    {
        ArrayList<String> list1 = new ArrayList<>();
        list1.add("2212");
        list1.add("gmail.com");

        ArrayList<String> list2 = new ArrayList<>();
        list2.add("192.168.0.175");
        list2.add("403");
        list2.add("192.168.0.26");
        list2.add("1809");

        File file = new File("test.csv");
        FileWriter fw = new FileWriter(file);
        BufferedWriter bw = new BufferedWriter(fw);

        bw.write("Domain,Total");
        bw.newLine();
        for(int i=0;i<list1.size();i++)
        {
            bw.write(list1.get(i+1)+","+list1.get(i++));
            bw.newLine();
        }
        bw.write("
Application,Total");
        bw.newLine();
        for(int i=0;i<list2.size();i++)
        {
            bw.write(list2.get(i++)+","+list2.get(i));
            bw.newLine();
        }
        bw.close();
        fw.close();
    }
}
Comment

PREVIOUS NEXT
Code Example
Java :: java restart while loop 
Java :: how to initialize bigdecimal in java 
Java :: awk print second 
Java :: string.join java 8 
Java :: java get bigger int 
Java :: How to print in console java 
Java :: Java Create LinkedList in Java 
Java :: print an array java 
Java :: responseentity spring boot 
Java :: load file as string java 
Java :: get request in java 
Java :: fhow to find location of java jdk 
Java :: java eclipse console clear 
Java :: spring boot save file to static folder 
Java :: discord jda 
Java :: java replace first occurrence of substring 
Java :: Spring boot enable openapi swagger accessed 
Java :: generate serial uuid with intelij 
Java :: java arraylist declaration 
Java :: android @Parcelize not resolving 
Java :: java print pdf to printer 
Java :: java get length of a string 
Java :: android sqlite select query 
Java :: how to print byte array in java 
Java :: java running sum of array 
Java :: java square root 
Java :: java variables 
Java :: java linear search 
Java :: java standard exception 
Java :: how to use user uid in android 
ADD CONTENT
Topic
Content
Source link
Name
5+1 =