Visualizzazione dei risultati da 1 a 5 su 5
  1. #1

    Problema con memorizzazione e StringBuffer..

    Io ho

    Stile 1

    name= A

    size 10



    Stile 2

    name=B

    size=10



    Stile 3

    name=C

    size=11



    voglio prendere le stringhe di stile con size 10 e memorizzarmi il loro name

    Faccio

    codice:
    private void PROVA()
      {
        String prova = new String();
        StringBuffer buffer = new StringBuffer();
        for ( int i = 0; i < stileObjects.size(); i++)
        {    
                  if ( stile.size.uquals("10") )
                  {
                  prova=stile.name;
                  buffer.append(prova+"\n");
                  }
        }
        System.out.println("PROVA"+prova);
      }
    Ho provato a fare una semplice System.out di prova e mi da correttamente A e B, il punto però è questo adesso se io volessi prendere i singoli valori di buffer come faccio???

    Ossia come faccio ad avere separatamente A e B???

    Non mi basta fare stile1.equals("A") o ("B"), come posso procedere???

  2. #2
    Utente di HTML.it L'avatar di andbin
    Registrato dal
    Jan 2006
    residenza
    Italy
    Messaggi
    18,284

    Re: Problema con memorizzazione e StringBuffer..

    Originariamente inviato da xxdavide84xx
    Ho provato a fare una semplice System.out di prova e mi da correttamente A e B, il punto però è questo adesso se io volessi prendere i singoli valori di buffer come faccio???
    Nello StringBuffer avrai una stringa con i name concatenati e delimitati da \n. Se non è questo che vuoi, fai in altro modo! Cioè ... perché concatenarli se poi hai bisogno di averli suddivisi??

    Dipende da cosa devi fare. Puoi metterli in un array o un ArrayList o altro. Spiega meglio, magari.
    Andrea, andbin.devSenior Java developerSCJP 5 (91%) • SCWCD 5 (94%)
    java.util.function Interfaces Cheat SheetJava Versions Cheat Sheet

  3. #3
    Con arrayList sarebbe così giusto?
    codice:
    private void PROVA()
      {
        String prova = new String();
        ArrayList buffer = new ArrayList();
        for ( int i = 0; i < stileObjects.size(); i++)
        {    
                  if ( stile.size.uquals("10") )
                  {
                  prova=stile.name;
                  buffer.add(prova);
                  }
        }
        System.out.println("PROVA"+buffer);
      }
    Io in pratica prima mi memorizzo questi valori facendo vari if così trovo solo i name che interessano a me. Poi devo prendere questi valori name singolarmente e fare un confronto con name di un'altra classe (body)...
    Devo dire se A o B sono uguali a body.name alllora OK...

    Non sono come dire l'elemento i-esimo....

  4. #4
    Utente di HTML.it L'avatar di andbin
    Registrato dal
    Jan 2006
    residenza
    Italy
    Messaggi
    18,284
    Originariamente inviato da xxdavide84xx
    codice:
    private void PROVA()
      {
        String prova = new String();
        ArrayList buffer = new ArrayList();
        for ( int i = 0; i < stileObjects.size(); i++)
        {    
                  if ( stile.size.uquals("10") )
                  {
                  prova=stile.name;
                  buffer.add(prova);
                  }
        }
        System.out.println("PROVA"+buffer);
      }
    Non è che "quadra" molto .... stileObjects cosa è? E dove lo usi, oltre per il size()????? E cosa ci fai in questo metodo con l'array list? Se devi fare un ciclo per verificare se body.name è uno di quei name, fai tutto nel ciclo, perché usare un ArrayList??
    Andrea, andbin.devSenior Java developerSCJP 5 (91%) • SCWCD 5 (94%)
    java.util.function Interfaces Cheat SheetJava Versions Cheat Sheet

  5. #5
    Li era uno pseudo codice INVENTATO...ora ti faccio vedere il codice REALE:
    codice:
    private void aa()
      {
        for ( int i = 0; i < bodyObjects.size(); i++)
        {
          Body body = (Body)bodyObjects.elementAt(i);
          if ( body.testo != null )
          {
            if ( body.testo.equalsIgnoreCase("relatore:") || body.testo.equalsIgnoreCase("relatore") )
              System.out.println("OK relatore");
            if ( body.testo.equalsIgnoreCase("presentata da:") || body.testo.equalsIgnoreCase("presentata da") )
              System.out.println("OK presentata");
            if ( body.testo.equalsIgnoreCase("sessione i") || body.testo.equalsIgnoreCase("sessione 1") )
              System.out.println("OK Prima sessione");
            if ( body.testo.equalsIgnoreCase("sessione ii") || body.testo.equalsIgnoreCase("sessione 2") )
              System.out.println("OK Seconda sessione");
            if ( body.testo.equalsIgnoreCase("sessione iii") || body.testo.equalsIgnoreCase("sessione 3") )
              System.out.println("OK Terza sessione");
            if ( body.testo.equalsIgnoreCase("indice") || body.testo.equalsIgnoreCase("ndice") )
              System.out.println("OK INDICE");
            if ( body.testo.equalsIgnoreCase("introduzione") || body.testo.equalsIgnoreCase("ntroduzione") )
              System.out.println("OK INTRODUZIONE");
            if ( body.testo.equalsIgnoreCase("conclusioni") || body.testo.equalsIgnoreCase("onclusioni") || body.testo.equalsIgnoreCase("conclusione") || body.testo.equalsIgnoreCase("onclusione") )
              System.out.println("OK CONCLUSIONI");
            if ( body.testo.equalsIgnoreCase("bibliografia") || body.testo.equalsIgnoreCase("ibliografia") || body.testo.equalsIgnoreCase("bibbliografia") || body.testo.equalsIgnoreCase("ibbliografia") )
              System.out.println("OK BIBLIOGRAFIA");
          }
          if ( body.testo != null && body.font == null )
          {
            for ( int j = 0; j < styleObjects.size(); j++)
            {
              Style style = (Style)styleObjects.elementAt(j);
              if ( body.stile.equals(style.name) )
              {
                if ( style.font != null )
                {
                  if ( style.font.equals("Times New Roman") )
                    System.out.println("OK TIMES NEW ROMAN");
                  else
                    System.out.println("BIRICHINO" + style);
                }
              }
            }
          }
          if ( body.font != null )
          {
            if ( body.testo != null && body.font.equals("Times New Roman") )
              System.out.println("OK ANCHE COSì TIMES NEW ROMAN");
          }
        }
      }
    Io dovrei mettere dove il testo non è null (ossia c'è del testo) dovrei fare un controllo se body.stile (ossia se lo stile del body) è uguale a uno di quegli stili
    che vengono fuori facendo
    codice:
      private void STILI()
      {
        String style1 = new String();
        ArrayList buffer1 = new ArrayList();
        for ( int i = 0; i < styleObjects.size(); i++)
        {
          Style style = (Style)styleObjects.elementAt(i);
          if ( style.jc != null && style.jc.equals("both") )
            if ( style.font != null && style.font.equals("Times New Roman") )
              if ( style.size != null )
                if ( style.size.equals("24") || style.size.equals("26") )
                  if ( style.grassetto == null && style.italico == null && style.sottolineato == null )
                  {
                    style1 = style.name;
                    buffer1.add(style1);
                    System.out.println(style1);
                  }
        }
    for (int j=0; j<buffer1.size();j++)
    {
    System.out.println(buffer1.get(j));
    }
        
      }
    dentro l'ultimo for dovrei dire if(body.stile.equals(buffer1.get(j))) per dire se lo stile è uguale a uno di quelli circoscritti nel buffer

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.