Home Answers Viewqa Java-Beginners How to Manipulate List to String and print in seperate row

 
 


Hardik Modi
How to Manipulate List to String and print in seperate row
0 Answer(s)      9 months ago
Posted in : Java Beginners

I am trying to export the 4 columns with the below code.the last column organization is a List.

        String appname = "abc";
        String path = "//home/exportfile//";
        String filename = path+"ApplicationExport-"+appname+".txt";
        String ret = "false";

QueryOptions ops = new QueryOptions();
Filter [] filters = new Filter[1];
filters[0] = Filter.eq("application.name", appname);
ops.add(filters);

List props = new ArrayList();
props.add("identity.name");

//Do search
Iterator it = context.search(Link.class, ops, props);

//Build file and export header row
BufferedWriter out = new BufferedWriter(new FileWriter(filename));
out.write("IdentityName,UserName,WorkforceID,Organization");
out.newLine();          

//Iterate Search Results
if (it!=null)
{                               
        while ( it.hasNext() ) {

                //Get link and create object
                Object [] record = it.next();
                String identityName = (String) record[0];
                Identity user = (Identity) context.getObject(Identity.class, identityName);

                //Get Identity attributes for export
                String workforceid = (String) user.getAttribute("workforceID");                 

                //Get application attributes for export
                String userid="";

                List links = user.getLinks();
                if (links!=null)
                {
                        Iterator lit = links.iterator();
                        while (lit.hasNext())
                        {
                                Link l = lit.next();
                                String lname = l.getApplicationName();
                                if (lname.equalsIgnoreCase(appname))
                                {
                                          userid = (String) l.getAttribute("User Name");
                                          List organizations = l.getAttribute("Organization");

                                          StringBuilder sb = new StringBuilder();
                                          String listItemsSeparator = ","; 

                                                                                        for (Object organization : organizations)
                                                                                                                {
                                                                                                                        sb.append(organization.toString());
                                                                                                                        sb.append(listItemsSeparator);
                                                                                                                }

                                                                                                                org = sb.toString().trim();

                                }
                        }
                }                   

                //Output file
                out.write(identityName+","+userid+","+workforceid+","+org);                             
                out.newLine();                                                                          
                out.flush();
        }

                 ret="true";
}

//Close file and return
out.close();
return ret;

the output of the above code will be.for ex:

IdentityName,UserName,WorkforceID,Organization

dthomas,dthomas001,12345,Finance,HR

How do i get the output in below fashion

IdentityName,UserName,WorkforceID,Organization

dthomas,dthomas001,12345,Finance

dthomas,dthomas001,12345,HR

what and where i need to change the code?

View Answers









Related Pages:
How to Manipulate List to String and print in seperate row
How to Manipulate List to String and print in seperate row  I am... is a List. String appname = "abc"; String path = "//home/exportfile... String userid=""; List links = user.getLinks
PLEASE Help me write a Java program which will store, manipulate, and print student registration information.
PLEASE Help me write a Java program which will store, manipulate, and print... will store, manipulate, and print student registration information. As part... in the java.util package (d) The field Courses is a set of no more than five (5) string values
How to print list of files in client system
How to print list of files in client system  have some list of files in server.i just want to print that files in client machine with out opening the file.i give the option for user like printall.if user click printall prints
How to add dropdown list in a row of a sort table applet?
How to add dropdown list in a row of a sort table applet?  How to add dropdown list in a row of a sort table applet
Arraylist from row values
Arraylist from row values  Hello, can anyone please help on how to make an arraylist from the row values of a particular column from a database...; class Retrieve{ public static void main(String[] args){ try
JDBC Get Row Count
in JDBC Get Row Count. The code help you to understand how to count the number... JDBC Get Row Count       The JDBC Get Row Count enables you to return the row count of a query. JDBC Get Row
Manipulate transactional behavior of EJBs using deployment descriptors
Manipulate transactional behavior... transactions Next    Manipulate transactional... attribute indicates how the EJB container should treat the method called
Array List and string operation
Array List and string operation  hi, I want to search an arraylist element in a a given file. example I have a name called "mac" in my arraylist and I have a txt file which contains mac, how many times "mac" appears in the txt
How to send and view data in seperate tables of a swing application, to a japser reporting(two)
How to send and view data in seperate tables of a swing application... datasource=new JRTableModelDataSource(jTable1.getModel()); String.../AccsBook/Tools" // the jrxml file Map<String,Object>params=new
How to send and view data in seperate tables of a swing application, to a japser reporting(two)
How to send and view data in seperate tables of a swing application... datasource=new JRTableModelDataSource(jTable1.getModel()); String.../AccsBook/Tools" // the jrxml file Map<String,Object>params=new
print a rectangle - Java Beginners
print a rectangle  how do I print a rectangleof stars in java using...(String[] param) throws IOException{ InputStreamReader m = new...()); System.out.print("The number of triangles you want to output in each row
delete row
delete row  how to delete row using checkbox and button in php...("sourabh", $link); $rows=mysql_query("select * from sonu"); $row=mysql...;/tr> <?php while($row=mysql_fetch_array($rows)) { ?> <tr>
String
String  how to print in between numbers if the question "String s = "1,2,3,4,5,6,8,-25"" out must be 1 2,3,4,5,6,7,8,9,10,upto25
Print
Print  In system.out.println,what meant ln..?   System: It is a class made available by Java to let you manipulate various operating system... into the stream and, as opposed to print() method, gets you to the new line after the text
how to update checkbox list in database
how to update checkbox list in database  Issues: i am using different checkboxs for getting role then all role list store in one string array i want... ) EditRole.java file 1) Role_Id = request.getParameter("RoleId"); String[] role
how to set value of dropdown list
the value from a link to a dropdown list. I want to set the dropdown list selected according to link. CODE: print(" Blockquote <% String hr...how to set value of dropdown list  Hello Sir, I'd solved the earlier
print
print  How to print JFrame All Componant?   Please visit the following link: http://www.roseindia.net/java/example/java/swing/Print.shtml
how to print - Java Beginners
how to print  how to print something on console without using... anything on the console. import java.io.*; public class Print{ public static void main(String args[]) { PrintWriter pw = new PrintWriter(System.out, true
how to print the following pattern
how to print the following pattern  Hello hEllo heLlo helLo hellO... static void main(String[] args) { String st="hello...++){ char ch=Character.toUpperCase(st.charAt(i)); String str
how to print pdf format
how to print pdf format  Hi every body iam doing school project iam using backend as oracle front end java .how to print student marks list /attendence in pdf format. please help me. thanks in advance.   Here
print initials
print initials  How to print initials of a name without using arrays...*; public class InitialName { public static void main(String[] args... Name"); String name=input.nextLine(); input.close(); int
to read a file and seperate vowels and consonants to other files
to read a file and seperate vowels and consonants to other files  import java.io.*; public class alpha { public static void main(String[] args... BufferedWriter(opstream); String str=br.readLine(); char ch
Java table & list
Java table & list  I am taking string elements from user in list, And I want those list elements to be added to table row one by one, The jTable & list are at different classes but under same package. How to do so? Please
how to send email list of email address through in database table list
how to send email list of email address through in database table list ..."); PrintWriter out = response.getWriter(); String to=request.getParameter("to"); String subject=request.getParameter("subject"); String msg
How to print the following pattern in java?
How to print the following pattern in java?  How to print... java.io.*; class StringPattern { public static void main(String[] args) throws IOException{ String st="he is going in"; String str
how to call list objects as string into my sql query?
how to call list objects as string into my sql query?  how to call list data as string into my sql query so that i can retrieve all values from database? List has data retrieved from xml(using xmlSAXparser
Count Row - JSP-Servlet
Count Row  Hello all, Please I need your help on how to desplay the number of row(s) affected along with the affected row(s) in mssql database 2000...(); Connection con = null; String url = "jdbc:mysql://localhost:3306/"; String
how to print headings horizontally in jsp
how to print headings horizontally in jsp  In one of my jsp i have used for loop. in every iteration it will fetch value from db and print it on heading section, it prints vertically but my requirement is to print it horizontally
Print the following format
Print the following format  how to print the following format given string "00401121" in java 0-** 1-* 2-* 3- 4
linked list
linked list   how to add student and mark and number from file in linked list and print them also how to make search function plz can help me sooon
how to search the string arraylist contains database rows?
the row values into string arraylist. now i want to print the common rows existed. how do i do...how to search the string arraylist contains database rows?  i need
Displaying checked checkbox in same page as well as print on another page ....also add next pages cheches checkbox into previous list
Displaying checked checkbox in same page as well as print on another page... language="java" import ="java.sql.*" %> <% String val[] = request.getParameterValues("val");String st="";for(int i=0;i"+rs.getString("empid")+""+rs.getString
print variable in iphone
print variable in iphone  how can i print a variable in iphone????   hello,, if you want to print a variable in objective C if integer then int i=3; NSLog(@"%d",i); if string then NSSting *str; NSLog(@"%@",str
print array in following format
print array in following format  i want print two array in following... static void main(String[] args) { int array1[]= {1,2,3,4,5,6,7,8,9...; int columns = 3; for (int row = 0; row < rows; row
Linked list implementation
Linked list implementation  How to create linkedlist by using array in java? and also How to manipulate
how update JTable after adding a row into database
how update JTable after adding a row into database  J have two... in JTable, and it's OK, but after adding a row into database table does't update. How update JTable after adding a row into database? package djilepak.javaclss.for
How to list all drives available in the system
How to list all drives available in the system In this section, you will learn how to list out all the drives available in the system.  Description of code: To get the list of drives, we have called the method listRoots() of File
linked list
linked list   how to write a program using a linked list...:"); for (String names : list) { System.out.println(names... java.util.*; class LinkedListExample { public static void main(String[] args
How to delete the row from the Database by using servlet
How to delete the row from the Database by using servlet  Dear Sir... 25 users details are there. I am given 6th (some n th row)user details true... JdbcUpdateServlet extends HttpServlet { String name,pas,cde; String un,up,co
print reverse string without api
print reverse string without api  accept a string and print reverse without using api
Persist a List Object in Hibernate - Hibernate
Persist a List Object in Hibernate   Hi All, I have a query on hibernate. How to persist a List object in Hibernate ? Can you give me... { /** * @param args */ public static void main(String[] args
print rectangle pattern in java
print rectangle pattern in java  * * * * * * * how to generate this pattern in java??   Hi friend try this code may...(String[] args) { for(int r=1; r<5; r
Generate shuffling in the specified list
and print the list according to the generated random number... void main(String args[]) { // create an array of employee names of string type. String employee[] = {"Mahendra", "Anu", "Sandeep", "Girish
Linked List
; private String computerBrand; public Computer(int, String); } public class... in the following logical linked list represents Computer Number. 76(head) 98 54...? to ?66?. The segment should also display the new contents of the linked list
how to check and print the no of times an integer is repeated in an array
how to check and print the no of times an integer is repeated in an array  how to check and print the no of times an integer is repeated...(String[] args) throws Exception{ int array[]={2,4,2,5,2,4,3,4,5,2}; for(int
DropDown list
DropDown list  how to get mysql database values into dropdown usign... values into dropdown list. 1)country.jsp: <%@page import="java.sql.*"%>...)state.jsp: <%@page import="java.sql.*"%> <% String country
how to set value of dropdown list
how to set value of dropdown list  Hello Sir, I'd solved the earlier... the value from a link to a dropdown list. I want to set the dropdown list selected according to link. CODE: <% String hr = request.getParameter
Dependant & dynamic drop down list
on the values selected by user in first drop down list. How to achieve this ?   ... be in this or AJAX forum. I have one dynamic drop down list from data base (working...;/html> 2)state.jsp: <%@page import="java.sql.*"%> <% String country
Deleting a Row from SQL Table Using EJB
to delete a row from the SQL Table. Find out the steps given below that describes how to delete a particular row from the database table using EJB. The steps... Deleting a Row from SQL Table Using EJB   
List to be visible only when entering any string into textfield
List to be visible only when entering any string into textfield  how... list i have to get only the selected string the entire other names in the list must be hidden and the list must be visible only when i am entering anything

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.