-2

For the implementation of an algorithm,I need to delete a particular value from the list.

Eg:---

My list:---

     Ist row->4,7,3,4

     IInd row->2,8,6,5

     IIIrd row->3,5,1,7

Before delete some values,I need to sort it.That is,

     Collections.sort(list);

Sorted Result

     2,8,6,5

     3,5,1,7

     4,7,3,4

Expected OUTPUT Now I need to delete 1st elements of all rows. The output is

     8,6,5

     5,1,7

     7,3,4

How I do this???I tried it by using tokenizer method,but I don't get it.

Touchstone
  • 5,575
  • 7
  • 41
  • 48
Dahlia
  • 41
  • 11

2 Answers2

2

You can remove the first element from a java.util.List with

myList.remove(0);

To eliminate the first space delimited word (or number) from a string, use:

s = s.substring((s.indexOf(" ") + 1), s.length());

Note that this will fail if the string is null, or does not contain a space.

You can protect against this with

if(str == null || str.indexOf(" ") != -1)  {
   throw  new IllegalArgumentException("str (" + str + ") must be non-null, and must contain a space.");
}
//Safe!
str = str.substring((str.indexOf(" ") + 1), str.length());
aliteralmind
  • 19,847
  • 17
  • 77
  • 108
1

You just delete the list item at zero position... Like this

 ListVariable.remove(0);

For the every First element means Use for loop... Just get the Rows...

for(int i =0 ; i<ListVariable.size() ; i+4 )
{
      ListVariable.remove(i);
}
Naveen Kumar Kuppan
  • 1,424
  • 1
  • 10
  • 12