473,659 Members | 2,646 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to read item by item from String ArrayList

2 New Member
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 34851
alfredo17
2 New Member
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 Recognized Expert Top Contributor
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 MVP
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
1967
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
4125
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
6730
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 True. Therefore, overriding the Equals method in the class definition of the items I put in the ArrayList should make the IndexOf method use my version of the Equals method?!
18
4729
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 class where only the "searched" property has a value. I expected to get the index into the arraylist where I could then get the entire class instance. However, the 'indexof' is never calling my overloaded, overrides Equals method. Here is the...
5
2560
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 property by the same name declared in ArrayList"... what gives? Am I out to lunch? I should add that I'm still a little new to OO and inheritance, polymorphism, etc, and would really like to understand this... Here's my code: Public Class...
4
3235
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, third,5th etc string in a vector. How do I do this? Thanks a lot. Any help I can get is appreciated
3
12488
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 can write string to a db I tried to a MemoryStream but it seems to be empty ??? There is data
2
5338
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 db or save string to the db I don't want to have to copy the string to a file to use the WritePrivateProfileString and GetPrivateProfileString. Is there a way around this instead of writing my own class to operate on a string or stream ???
0
8428
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8339
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
7360
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6181
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5650
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4176
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4338
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1982
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1739
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.