473,396 Members | 2,151 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How to read item by item from String ArrayList

Some can help me to extract String by String from ArrayList.

I can add an String but now I would like to read item by item from an ArrayList.

Thanks
Jan 26 '07 #1
3 34839
Please, some one can help me to extract String by String from ArrayList.

I can add an String but now I would like to read item by item from an ArrayList.

Thanks
Jan 26 '07 #2
horace1
1,510 Expert 1GB
Please, some one can help me to extract String by String from ArrayList.

I can add an String but now I would like to read item by item from an ArrayList.

Thanks
you can use an Iterator, e.g.
Expand|Select|Wrap|Line Numbers
  1. import java.io.*;
  2. import java.util.*;
  3.  
  4. class ArrayListString 
  5. {
  6. public static void main(String s[])
  7.  {
  8.    ArrayList <String>list = new ArrayList <String>(100);    // can store any Nunber
  9.    list.add("Hello");
  10.    list.add("world");
  11.    Iterator iter = list.iterator();
  12.     while (iter.hasNext()) {
  13.       System.out.println("string " + iter.next());
  14.       }
  15.   }
  16. }
when run give
string Hello
string world
Jan 26 '07 #3
r035198x
13,262 8TB
you can use an Iterator, e.g.
Expand|Select|Wrap|Line Numbers
  1. import java.io.*;
  2. import java.util.*;
  3.  
  4. class ArrayListString 
  5. {
  6. public static void main(String s[])
  7.  {
  8.    ArrayList <String>list = new ArrayList <String>(100);    // can store any Nunber
  9.    list.add("Hello");
  10.    list.add("world");
  11.    Iterator iter = list.iterator();
  12.     while (iter.hasNext()) {
  13.       System.out.println("string " + iter.next());
  14.       }
  15.   }
  16. }
when run give
string Hello
string world
Alternatively you could also read the strings out of the list using the get method of arraylist.
Jan 29 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Adam | last post by:
Hi all, I have an arraylist filled with 4 objects and defined as shown below. ArrayList items = new ArrayList(); public Item GetItemAt(int index) { return (Item)items; }
2
by: ABC | last post by:
How to read the connection string from web.config? I known .NET framework 2.0 has new features about connection settings, but I don't know how to use. Thanks
12
by: Rubbrecht Philippe | last post by:
Hi there, According to documentation I read the ArrayList.IndexOf method uses the Object.Equals method to loop through the items in its list and locate the first index of an item that returns...
18
by: JohnR | last post by:
From reading the documentation, this should be a relatively easy thing. I have an arraylist of custom class instances which I want to search with an"indexof" where I'm passing an instance if the...
5
by: Mykl | last post by:
I'm trying to derive a class from ArrayList. When I try to use the Overrides keyword on the Item property, the IDE underlines Item in my Function definition and says "Item conflicts with a...
4
by: aarthi28 | last post by:
Hi, I am trying to read every other string from a text file and store it in a vector. I can use istream_iterator to read all strings and store it in a vector. However, I only need the first,...
3
by: =?Utf-8?B?c2lwcHl1Y29ubg==?= | last post by:
Hi I have an xsd that I want to save as an XML string to store in a DB I can save as a physical file using xsd.WriteXml(@"C:\Temp\Junk\junk.xml"); But I am unable to save to a string so I...
2
by: =?Utf-8?B?c2lwcHl1Y29ubg==?= | last post by:
Hi Is there any way to Read an INIFile from a string or Stream instead of a physical file ??? I want to read the INIFile into a string then store in a db but when I read the string from the...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.