Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How do i print in java

 
Jimmy Thakkar
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do i print in java
+
how do i print contents of listbox!
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To print to the console ( i.e. the OS window the java program is running in... ) use


Is the class you are trying to print the contents of a List ( in java.awt ) or a JList ( in javax.swing )?

-Nate
 
shweta agarwal
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
to print anything use:
System.out.println("string1" + "string2" + variables);
u can thus overload + operator to get the expression of ur desire by making any combination.
u can also use System.out.print (instead of System.out.println) if u dont want to switch over to the next line after printing the stuff in the first line.
to print the contents of a listbox use the following 2 methods:
int countItem()
this returns the total number of items in the list.
and once u have the total number of items in the list u can use the following method in a loop
String getItem(int)
which returns the item at int position.
so ur code would be something like this(if ur list is l1)
int i = l1.countItem();
for(int j=0;j<i;j++)>
System.out.println(l1.getItem(j));

shweta agarwal
Sun Certified Programmer for the Java� 2 Platform

------------------
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic