| Author |
Getting string of maximum length from arraylist
|
bappa
Greenhorn
Joined: Mar 11, 2008
Posts: 15
|
|
Hi, I have an arraylist which has some following data, "abc", "gdhj","hdvdvbvd","uyiyiyioy","abcd" etc. How can get the value from list with max length ie "uyiyiyioy"? Can anybody give some code? Thanks in advance!
|
S K B<br />SCJP 1.5 (83%)
|
 |
Guido Sautter
Ranch Hand
Joined: Dec 22, 2004
Posts: 142
|
|
Hi 'bappa', please read the JavaRanch naming policy, which specifies that your display name has to consist of a full first name and last name. Take a second to change your display name accordingly. In addition, just asking for code to solve a problem described in text form is not the way JavaRanch works, especially if it clearly sounds like a homework assignment. (a) JavaRanch is not a code mill, and (b) do your own homework. People are out here to give you hints on how to solve problems, or to fix bugs in code you've written. For your particular problem, try a for loop and the String.length() method. All the best, Guido
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32651
|
|
Guido is quite right; please correct your displayed name with "my profile" "update profile". Guido is quite right; please show us what you have achieved so far. CR
|
 |
Arpit Sharma
Greenhorn
Joined: Sep 10, 2008
Posts: 8
|
|
Hi Bappa iterate through list ,take each object out of it ,find its length and store it ...compare this length with next elements length compare ,if greater swap ..else continue..in the end you will get the max lengths,this is like a selection sort . where lengths comparison will be equal to number of elements but there will be at max n-1 swaps [ September 10, 2008: Message edited by: Arpit Bon2dfylmts ] [ September 10, 2008: Message edited by: Arpit Bon2dfylmts ]
|
SCJP 1.5
|
 |
Jesper de Jong
Java Cowboy
Bartender
Joined: Aug 16, 2005
Posts: 12909
|
|
|
Arpit Bon2dfylmts, please check your private messages. You can see them by clicking My Private Messages.
|
Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
|
 |
 |
I agree. Here's the link: jrebel
|
|
subject: Getting string of maximum length from arraylist
|
|
|