473,396 Members | 1,924 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 find a part of a string in an arraylist ?

Hi all,

This steps I made:
1. Read a file in
2. Put each line of the file in an arraylist
3. Make a collection of the arraylist so you can sort them
4. Search for a word

Now my problem is, the text file will be something like this:

001.name:els
002.year:19
003.road:weg
004.roadnr349
005.-------------------
006.name:jan
007.year:69
008.road:disbeekweg
009.road nr:10
010.-------------------


When my function writes this text into this file, it writes automaticly the numbers cause when i sort later on this array, it wil sort by the alfabeth and I want the notes by each user.

So now my question is, is there a solution so I don't have to give up the whole string ( exemple: "006.name:jan") if i want this user and his notes ?

It would be great if I just can say, give me the following 3 lines from the row that has the word "jan" in it ?


My working code:

public static void search(){

try {

ArrayList<String> v = new ArrayList<String>();

FileReader input = new FileReader("doit.txt");
BufferedReader bufRead = new BufferedReader(input);

String line;
int count = 0;

line = bufRead.readLine();
count++;

while (line != null){

v.add(line);
line = bufRead.readLine();
count++;
}

Collections.sort(v);
int whereFound = Collections.binarySearch(v, "008.jan");
//System.out.println( whereFound );


for (int i = 0; i<6; i++){
System.out.println(v.get(whereFound++));
}


bufRead.close();

}catch (ArrayIndexOutOfBoundsException e){

System.out.println("Usage: java ReadFile filename\n");

}catch (IOException e){

e.printStackTrace();
}

}
Nov 23 '06 #1
0 1942

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

Similar topics

4
by: Arjen | last post by:
Hi, I have a class with some attributes. For example class person with name as attribute. I have add multiple persons in an arraylist. Now I need a function to get/find a person by the name...
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...
3
by: Sam | last post by:
Hi Everyone, I have a stucture below stored in an arraylist and I want to check user's input (point x,y) to make sure there is no duplicate point x,y entered (string label can be duplicated). Is...
2
by: Shen | last post by:
Hi, I have an array/arraylist of string items. What I want is to find out which item repeats itself most often. Any simple example for that? Thanks in advance. sean
2
by: engelit.junk | last post by:
Hi, If you look at TreeNodeCollection.Find Method, you'll see: Finds the tree nodes with specified key, optionally searching subnodes. public TreeNode Find ( string key, bool...
5
by: SunnyDrake | last post by:
HI! I wrting some program part of it is XML config parser which contains some commands(for flexibility of engenie). how do i more simple(if it possible not via System.Reflection or...
0
by: xavier vazquez | last post by:
have a problem with a program that does not working properly...when the program run is suppose to generate a cross word puzzle , when the outcome show the letter of the words overlap one intop of the...
3
by: Nitinkcv | last post by:
Hi, While trying to run my app im getting the error Could not find a part of the path "c:\inetpub\wwwroot\Do not Delete\dbglobal.config". I checked and found that there is no Important_Do not...
3
by: mouac01 | last post by:
Newbie here. How do I do a find and replace in a binary file? I need to read in a binary file then replace a string "ABC" with another string "XYZ" then write to a new file. Find string is the...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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...

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.