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?

Get us started with some code and we will love to help you,

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?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.