can i have an optimal solution for this java code ? Facing Java heap space problem even at 3GB heaps


 
Thread Tools Search this Thread
Top Forums Programming can i have an optimal solution for this java code ? Facing Java heap space problem even at 3GB heaps
# 1  
Old 04-11-2011
can i have an optimal solution for this java code ? Facing Java heap space problem even at 3GB heaps

My desired output is

run:
Code:
for this  1
for this  2
for this  3
for this  4
for this  5

for this  1,2
1->2
for this  2,3
2->3
for this  3,4
3->4
for this  4,5
4->5

for this  1,2,3
1->2,3
1,2->3
for this  2,3,4
2->3,4
2,3->4
for this  3,4,5
3->4,5
3,4->5

for this  1,2,3,4
1->2,3,4
1,2->3,4
1,2,3->4
for this  2,3,4,5
2->3,4,5
2,3->4,5
2,3,4->5

for this  1,2,3,4,5
1->2,3,4,5
1,2->3,4,5
1,2,3->4,5
1,2,3,4->5


i had a program in java like this

:
Code:
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author vaibhav
 */
public class tmep {

    private static String str[] = {"1", "2", "3", "4", "5"};
    private static StringBuffer sbuf = new StringBuffer(50);

    public static void main(String args[]) {
        int count = str.length;
        // sbuf=sbuf.append(".");
        // str="123456789";
        for (int lim = 0; lim < count; lim++) //specifies the limit
        {
            for (int start = 1; start <= (count - lim); start++) // gives the starting point
            {
                for (int i = start; i <= lim + start; i++) //up to limit the words should be printed
                {

                    sbuf = sbuf.append(str[i - 1]).append(",");
                    //System.out.print(str[i - 1] + ",");
                }//for loop 3

                //System.out.print(sbuf);
                sbuf.deleteCharAt(sbuf.length() - 1);// this will remove the , at last position
               System.out.println("for this  "+ sbuf);
                //the module for creating all episode rules
                generateEpiRules(sbuf);

                // System.out.println("");
                sbuf.delete(0, sbuf.length());
                //System.out.print("\t");
            }//for loop 2
            System.out.println("");

        }//for loop 1

    }

    private static void generateEpiRules(StringBuffer sb) {
        String string;
        StringBuffer left=new StringBuffer ();
        StringBuffer right=new StringBuffer ();

        string = sb.toString();
        String st[] = string.split(",");
        for (int i = 1; i < st.length; i++)
        {
            //System.out.print("LHS  ");
            for (int j = 0; j < i; j++)
            {
                left.append(st[j]).append(",");
                //System.out.print(st[j] + ",");
            }
           // System.out.print(" RHS   ");

            for (int k = i; k < st.length; k++)
            {
               
            right.append(st[k]).append(",");
            // System.out.print(st[k] + ",");
            }
            left.deleteCharAt(left.length() - 1);// this will remove the , at last position
            right.deleteCharAt(right.length() - 1);// this will remove the , at last position
            System.out.println(left+"->"+right);
            left.delete(0, left.length());
            right.delete(0, right.length());
        }
    }
}







but if i give a sting length of more size;
the system tends to use RAM too much and after some time an exception comes that java Heapspace out of memory

I increased the heap space to 3 GB also but of no use Smilie

Please tell me the optimal program for this
i'm stucked up Smilie


thanks in advance

Last edited by pludi; 04-11-2011 at 07:59 AM..
# 2  
Old 04-11-2011
How long a string are we talking about?
# 3  
Old 04-12-2011
the input string can be in terms of some thousands e.g 4000
Login or Register to Ask a Question

Previous Thread | Next Thread

4 More Discussions You Might Find Interesting

1. Programming

Problem of using scanner to get space in JAVA

May I know how to get a string with space by using scanner class in java? (0 Replies)
Discussion started by: eel
0 Replies

2. UNIX for Dummies Questions & Answers

Checking heap memory size for java app

Hi I have one Java application installed in my Solaris system. Is there a way to find out the heap memory allocated size/used size/free size for the particular Java process? If anyone knows the command, please let me know. Even I appreciate if I have any scripts to find out the same. ... (0 Replies)
Discussion started by: nthiruvenkatam
0 Replies

3. Programming

Java code to access the shared heap

Hi Help needed and forgive me as I dont know Java so please bare with me. I have searched this site and google but was unable to locate the information I need. An application that we use - is based on java and stores some performance counters etc internally in the shared JVM. They are not... (4 Replies)
Discussion started by: frustrated1
4 Replies

4. Shell Programming and Scripting

Line space problem facing

Hi, I got a list of file that all got the same standard format. Can anyone teach me how to put the space in all of them?! Input file: >nucleotide1 AAAAAAAAACCCGGG >nucleotide2 GGGGGGCCCCCTTTTA >nucleotide3 GGTACACCACACTCAC >nucleotide4 TTTGGAGAGAGACCCC desired output:... (4 Replies)
Discussion started by: patrick87
4 Replies
Login or Register to Ask a Question

Featured Tech Videos