consider my input file has the following data

date type of transaction amount
1 w 100
2 d 230
3 d 550
4 w 430
5 d 1100
6 d 400

so i need to sort the amount in ascending order.So when i sort the amount,the corresponding date and transaction also needs to be sorted.I want the solution when we use arraylists for sorting.Could you help me?

hey..i normally used two for loops and did parallel sorting like this

public class BankAcc {
	public static void main(String args[])
	throws IOException
	{
		BufferedReader br=new BufferedReader(new FileReader("Input.txt"));
		String inline;
		String type[]=new String[25];
		int date[]=new int[25];
		int amount[]=new int[25];
		int count=0;
		while((inline=br.readLine())!=null)
		{
			count++;
			StringTokenizer st=new StringTokenizer(inline);
			{
				while(st.hasMoreTokens())
				{
					date[count]=Integer.parseInt(st.nextToken());
					type[count]=st.nextToken();
					amount[count]=Integer.parseInt(st.nextToken());
				}
			}
		}
		System.out.println("sorted order");//instead of such long code below,i want to use arraylists to do the below code
		for(int i=1;i<=count;i++)
		{
			for(int j=i+1;j<=count;j++)
			{
				if(date[i]>date[j])
				{
					int t=date[i];
					date[i]=date[j];
					date[j]=t;
					
					int t1=amount[i];
					amount[i]=amount[j];
					amount[j]=t1;
					
					String t2=type[i];
					type[i]=type[j];
					type[j]=t2;
				}
			}
			System.out.println(date[i] + " "+ type[i] + " " + amount[i]);
		}

Those are arrays - not ArrayLists - and why are you not using an object to represent each line item instead of three separate arrays for each piece of data?

This article has been dead for over six months. Start a new discussion instead.