Go Back   Java Programming Forums > Java Standard Edition Programming Help > Loops & Control Statements


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 25-02-2010, 07:36 PM
Junior Member
 

Join Date: Feb 2010
Posts: 1
Thanks: 1
Thanked 0 Times in 0 Posts
Espressoul is on a distinguished road
Default Searching and printing string results from an Arraylist. Having difficulty.

Hi, been having trouble with the last two methods of an assignment.

Basically I need to search an arraylist for a string that matches for example, 'waterford' and print to screen each of these results.

Also we need to print to screen an address, based on a name being entered.

What would be the best way to implement this, and would HashMap or HashSet be better?
We've been thinking along the lines of this

Java Code
 

public void searchByCounty()
        {
            int index =0;
            boolean found = false;
            while(index < addressLine.size() && !found)
                {
                    String county = nam.get(index);
                    if(Address.contains(searchString))
                        {
                            found = true;
                        }
                    else
                        {
                            index++;
                        }
                }
            }



Reply With Quote Share this thread on Facebook
Sponsored Links
Java Training from DevelopIntelligence
  #2 (permalink)  
Old 26-02-2010, 12:32 AM
copeg's Avatar
Moderator
 
9 Highscores

Join Date: Oct 2009
Posts: 570
Thanks: 7
Thanked 131 Times in 125 Posts
copeg will become famous soon enoughcopeg will become famous soon enough

I'm feeling Sleepy
Default Re: Searching and printing string results from an Arraylist. Having difficulty.

If you do not need multiple entries or proper ordering, a HashSet would work. Although the Hashset is founded upon a HashMap, if you don't need key/value pairs you can easily go with HashSet. If you want to link up locations with multiple hashsets (such as key a HashMap with street -> city, and city->county, and count->country, etc...), HashMap would work well. One more note, if you place custom written objects in the Map or Set you need to override and implement the hashCode() and equals() methods.
Reply With Quote
The Following User Says Thank You to copeg For This Useful Post:
Espressoul (26-02-2010)
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



Similar Threads
Thread Thread Starter Forum Replies Last Post
searching a string dvsumosize What's Wrong With My Code? 1 23-02-2010 05:31 AM
How to print results to screen NinjaLink What's Wrong With My Code? 1 19-02-2010 05:46 PM
Football Results RSYR What's Wrong With My Code? 2 04-11-2009 11:24 PM
[SOLVED] Extracting an How to ArrayList from an ArrayList and convert to int?? igniteflow Collections and Generics 2 16-08-2009 06:11 PM
How to use an ArrayList - java.util.ArrayList JavaPF Java Code Snippets and Tutorials 1 17-05-2009 06:12 PM


100 most searched terms
Search Cloud
2 dimensional arraylist java 2d arraylist java actionlistener actionlistener in java addactionlistener addactionlistener java convert double to integer java double format java double to integer in java double to integer java drag en drop programmeren java eclipse shortcut keys exception in thread "awt-eventqueue-0" java.lang.outofmemoryerror: java heap space exception in thread "main" java.lang.nullpointerexception exception in thread "main" java.lang.outofmemoryerror: java heap space format double in java format double java get mouse position java java 2d arraylist java actionlistener java double format java double formatting java double to int java double to integer java format double java forum java forums java get mouse position java list to map java mouse position java programming forum java programming forums java programming practice problems java send keystrokes to another application java two dimensional arraylist java.io.ioexception: premature eof java.lang.classformaterror: truncated class file java.lang.outofmemoryerror: java heap space java.util.arraylist jbutton action jbutton actionlistener jtextarea font jtextfield font size jxl.read.biff.biffexception: unable to recognize ole stream programming mutators and generics smack api two dimensional arraylist two dimensional arraylist java unable to sendviapost to url what is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20?

All times are GMT. The time now is 01:56 AM.
Powered by vBulletin® Copyright ©2000-2009, Jelsoft Enterprises Ltd.